/* * Send 'sig' (if not 0) to all processes matching 'name'. * Return the number of matches. */ int rost_proc_killbyname (const char *name, int sig) { int i, nproc, nmatch, mib[3]; size_t size; struct proc *p; struct kinfo_proc *kp = NULL; mib[0] = CTL_KERN; mib[1] = KERN_NPROCS; /* KERN_MACPROC, KERN_PROC */ size = sizeof (nproc); if (sysctl(mib, 2, &nproc, &size, NULL, 0) < 0) return -1; size = nproc * sizeof(struct kinfo_proc); kp = chunk(size * sizeof(char), "bsdkill"); if (kp == NULL) goto error; mib[1] = KERN_PROC; mib[2] = KERN_PROC_ALL; if (sysctl(mib, 3, kp, &size, NULL, 0) < 0) goto error; nproc = size / sizeof(struct kinfo_proc); for (nmatch = i = 0; i < nproc; i++) { p = (struct proc *)&kp[i].kp_proc; if (!strcmp (name, p->p_comm)) { nmatch++; kill (p->p_pid, sig); } } unchunk (kp); return nmatch; error: if (kp) unchunk (kp); return -1; }
int netconf_plugin_unload(clicon_handle h) { int i; netconf_reg_t *nr; while((nr = deps) != NULL) { DELQ(nr, deps, netconf_reg_t *); if (nr->nr_tag) free(nr->nr_tag); free(nr); } for (i = 0; i < nplugins; i++) plugin_unload(h, plugins[i]); if (plugins) unchunk(plugins); nplugins = 0; return 0; }
/* * netconf_plugin_load * Load allplugins you can find in CLICON_NETCONF_DIR */ int netconf_plugin_load(clicon_handle h) { int retval = -1; char *dir; int ndp; struct dirent *dp; int i; char *filename; plghndl_t *handle; if ((dir = clicon_netconf_dir(h)) == NULL) goto quit; /* Get plugin objects names from plugin directory */ if((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG, __FUNCTION__))<0) goto quit; /* Load all plugins */ for (i = 0; i < ndp; i++) { filename = chunk_sprintf(__FUNCTION__, "%s/%s", dir, dp[i].d_name); clicon_debug(1, "DEBUG: Loading plugin '%.*s' ...", (int)strlen(filename), filename); if (filename == NULL) { clicon_err(OE_UNIX, errno, "chunk"); goto quit; } if ((handle = plugin_load (h, filename, RTLD_NOW, __FUNCTION__)) == NULL) goto quit; if ((plugins = rechunk(plugins, (nplugins+1) * sizeof (*plugins), NULL)) == NULL) { clicon_err(OE_UNIX, errno, "chunk"); goto quit; } plugins[nplugins++] = handle; unchunk (filename); } retval = 0; quit: unchunk_group(__FUNCTION__); return retval; }