int RTCFUNC(init,net)(struct chip_loc *chip, char *argv[]) { char buf[512], buf2[512]; if(argv[0] == NULL) nd = ND_LOCAL_NODE; else nd = netmgr_strtond(argv[0],NULL); if(nd == -1) return -1; if(netmgr_ndtostr(ND2S_DIR_SHOW,nd,buf2,sizeof(buf2)) == -1){ perror("netmgr_ndtostr:"); return -1; } sprintf(buf, "%sproc/1/as", buf2); fd = open(buf, O_RDONLY); if(fd == -1) return -1; return 0; }
int pathmgr_node2fullpath(NODE* node, char *path, int pathmax) { int len; char *p; char *endp; NODE *n; NODE *prev; NODE *parent; pid_t mypid; int save_netmgr_coid = 0; //to shut the compiler up extern int __netmgr_send_private(int); mypid = getpid(); if(mypid != PROCMGR_PID) { // We're being called from a loader thread - we need to make // sure that __netmgr_send() uses a private connection id when // it tries to contact qnet. save_netmgr_coid = __netmgr_send_private(-1); } else if(proc_thread_pool_reserve() != 0) { // FUTURE - we could check to see if the object is off node // or if qnet is running (pathmgr_netmgr_pid() returns non-zero). // If so, we really don't have to fail the call, but could continue // on and just not try to show any network component since there // really won't be one. errno = EAGAIN; return -1; } /* If local path requested or if netmgr fails, don't include network component */ len = netmgr_ndtostr(ND2S_DIR_SHOW, node->object ? node->object->server.nd:ND_LOCAL_NODE, path, pathmax); if(mypid != PROCMGR_PID) { (void)__netmgr_send_private(save_netmgr_coid); } else { proc_thread_pool_reserve_done(); } if(--len < 0) { len = 0; } p = path + len; endp = path + pathmax; if((len > 0) && (p <= endp) && (p[-1] == '/')) { --p; } prev = 0; do { n = node; for( ;; ) { parent = n->parent; if(parent == n) break; if(parent == node) break; if(parent == prev) break; n = parent; } if(n->len) { p = add_piece(p, endp, "/", 1); p = add_piece(p, endp, n->name, n->len); } prev = n; } while(n != node); len = (p - path) + 1; // len includes the trailing '\0' if(pathmax > 0) { // append the '\0' (if there's space) path[(min(len, pathmax))-1] = '\0'; } return len; }
static int pathmgr_fdinfo(resmgr_context_t *ctp, io_fdinfo_t *msg, void *vocb) { OBJECT *obp = (OBJECT *)vocb; char *path; int size; size_t pathmax; int len; unsigned flags = msg->i.flags; NODE *node, *prev; if(obp->hdr.type != OBJECT_SERVER) { return ENOSYS; } if((size = (ctp->msg_max_size - ctp->offset) - sizeof msg->o) < 0) { return EMSGSIZE; } size = min(size, msg->i.path_len); pathmax = size; memset(&msg->o, 0x00, sizeof msg->o); path = (char *)(&msg->o + 1); len = 1; if(pathmax) { if(proc_thread_pool_reserve() != 0) { return EAGAIN; } /* If local path requested or if netmgr fails, don't include network component */ if( (len = netmgr_ndtostr( (flags & _FDINFO_FLAG_LOCALPATH) ? ND2S_LOCAL_STR | ND2S_DIR_SHOW : ND2S_DIR_SHOW, obp->server.nd, path, pathmax)) <= 1) { len = 1; *path = '\0'; } else { int n; if((n = strlen(path))) { if(path[--n] == '/') { len--; path[n] = '\0'; } } } proc_thread_pool_reserve_done(); if(len < pathmax) { pathmax -= len - 1; path += len - 1; } else { pathmax = 0; } } prev = 0; do { for(node = obp->hdr.node; node != node->parent; node = node->parent) { if(node->parent == prev || node->parent == node) { break; } } if(node->len) { len += straddstr("/", 0, &path, &pathmax); len += straddstr(node->name, node->len, &path, &pathmax); } prev = node; } while(node != obp->hdr.node); if(obp->hdr.flags & _RESMGR_FLAG_DIR) { len += straddstr("/", 0, &path, &pathmax); } _IO_SET_FDINFO_LEN(ctp, len); return _RESMGR_PTR(ctp, &msg->o, sizeof msg->o + min(size, len)); }