/* * Create directory for zone/points if needed */ int bink_mkdir(Node *node) { char buf[MAXPATH]; char *base; size_t rest; /* * Outbound dir + zone dir */ BUF_COPY2(buf, cf_p_btbasedir(), "/"); #ifndef AMIGADOS_4D_OUTBOUND if((base = cf_zones_out(node->zone)) == NULL) #else if((base = cf_zones_out(0)) == NULL) #endif return ERROR; BUF_APPEND(buf, base); base = buf + strlen(buf); rest = sizeof(buf) - strlen(buf); if(check_access(buf, CHECK_DIR) == ERROR) { if(mkdir(buf, DIR_MODE) == -1) { fglog("$WARNING: can't create dir %s", buf); return ERROR; } chmod(buf, DIR_MODE); } #ifndef AMIGADOS_4D_OUTBOUND /* * Point directory for point addresses */ if(node->point > 0) { str_printf(base, rest, "/%04x%04x.pnt", node->net, node->node); if(check_access(buf, CHECK_DIR) == ERROR) { if(mkdir(buf, DIR_MODE) == -1) { fglog("$WARNING: can't create dir %s", buf); return ERROR; } chmod(buf, DIR_MODE); } } #endif /**AMIGADOS_4D_OUTBOUND**/ return OK; }
/*! @brief Get information about running processes. @ingroup system_misc @return List of process entries. @retval NULL if it failed. Each entry in the list is a hash containing the following entries: - \c USER -- user owning the process - \c PID -- process ID - \c PPID -- parent process ID - \c ENV -- explicit environment settings - \c PROG -- program being run - \c ARGS -- program arguments */ vlist * v_procinfo(void) { #ifdef HAVE_POPEN char user[1024], *line, cmd[1024], linebuf[1024], *token; static vbuffer *env = NULL, *prog = NULL, *args = NULL; vlist *list = NULL; FILE *fp = NULL; int pid, ppid; vhash *data; #ifdef HAVE_UID struct passwd *pw; int uid; #endif /* Open pipe */ if ((fp = popen(PS_CMD, "r")) == NULL) return NULL; /* Skip over header line */ if (fgets(linebuf, 1024, fp) == NULL) { pclose(fp); return NULL; } list = vl_create(); /* Read process info */ while ((line = fgets(linebuf, 1024, fp)) != NULL) { /* Get the data */ #ifdef HAVE_UID sscanf(line, PS_FMT, &uid, &pid, &ppid, cmd); if ((pw = getpwuid(uid)) != NULL) strcpy(user, pw->pw_name); else strcpy(user, "nobody"); #else sscanf(line, PS_FMT, user, &pid, &ppid, cmd); #endif /* Skip uninteresting processes */ if (cmd[0] == '[') continue; /* Add process */ data = vh_create(); vl_ppush(list, data); vh_sstore(data, "USER", user); vh_istore(data, "PID", pid); vh_istore(data, "PPID", ppid); /* Extract environment, program and arguments from command */ vb_init(env); vb_init(prog); vb_init(args); token = strtok(cmd, " "); while (token != NULL) { if (vb_length(env) == 0 && vb_length(prog) == 0 && strchr(token, '=') != NULL) BUF_APPEND(env, token); else if (vb_length(prog) == 0) BUF_APPEND(prog, token); else BUF_APPEND(args, token); token = strtok(NULL, " "); } if (vb_length(env) > 0) vh_sstore(data, "ENV", vb_get(env)); if (vb_length(prog) > 0) vh_sstore(data, "PROG", vb_get(prog)); if (vb_length(args) > 0) vh_sstore(data, "ARGS", vb_get(args)); } pclose(fp); return list; #else v_unavailable("v_procinfo()"); return NULL; #endif }