| 741 | } |
| 742 | |
| 743 | static int |
| 744 | mp_send(struct rte_mp_msg *msg, const char *peer, int type) |
| 745 | { |
| 746 | int dir_fd, ret = 0; |
| 747 | DIR *mp_dir; |
| 748 | struct dirent *ent; |
| 749 | |
| 750 | if (!peer && (rte_eal_process_type() == RTE_PROC_SECONDARY)) |
| 751 | peer = eal_mp_socket_path(); |
| 752 | |
| 753 | if (peer) { |
| 754 | if (send_msg(peer, msg, type) < 0) |
| 755 | return -1; |
| 756 | else |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | /* broadcast to all secondary processes */ |
| 761 | mp_dir = opendir(mp_dir_path); |
| 762 | if (!mp_dir) { |
| 763 | RTE_LOG(ERR, EAL, "Unable to open directory %s\n", |
| 764 | mp_dir_path); |
| 765 | rte_errno = errno; |
| 766 | return -1; |
| 767 | } |
| 768 | |
| 769 | dir_fd = dirfd(mp_dir); |
| 770 | /* lock the directory to prevent processes spinning up while we send */ |
| 771 | if (flock(dir_fd, LOCK_SH)) { |
| 772 | RTE_LOG(ERR, EAL, "Unable to lock directory %s\n", |
| 773 | mp_dir_path); |
| 774 | rte_errno = errno; |
| 775 | closedir(mp_dir); |
| 776 | return -1; |
| 777 | } |
| 778 | |
| 779 | while ((ent = readdir(mp_dir))) { |
| 780 | char path[PATH_MAX]; |
| 781 | |
| 782 | if (fnmatch(mp_filter, ent->d_name, 0) != 0) |
| 783 | continue; |
| 784 | |
| 785 | snprintf(path, sizeof(path), "%s/%s", mp_dir_path, |
| 786 | ent->d_name); |
| 787 | if (send_msg(path, msg, type) < 0) |
| 788 | ret = -1; |
| 789 | } |
| 790 | /* unlock the dir */ |
| 791 | flock(dir_fd, LOCK_UN); |
| 792 | |
| 793 | /* dir_fd automatically closed on closedir */ |
| 794 | closedir(mp_dir); |
| 795 | return ret; |
| 796 | } |
| 797 | |
| 798 | static int |
| 799 | check_input(const struct rte_mp_msg *msg) |
no test coverage detected