static void test_tsymlink (void) { Npfcall *fc, *fc2; if (!(fc = np_create_tsymlink (1, "xyz", "abc", 4))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TSYMLINK, __FUNCTION__); assert (fc->u.tsymlink.fid == fc2->u.tsymlink.fid); assert (np_str9cmp (&fc->u.tsymlink.name, &fc2->u.tsymlink.name) == 0); assert (np_str9cmp (&fc->u.tsymlink.symtgt, &fc2->u.tsymlink.symtgt) == 0); assert (fc->u.tsymlink.gid == fc2->u.tsymlink.gid); free (fc); free (fc2); }
/* * Gather concatenated hwloc xml topo file with resource-hwloc.topo RPC * and save results until destroyed by hwloc_topo_destroy (). */ static struct hwloc_topo * hwloc_topo_create (optparse_t *p) { const char *json_str; struct hwloc_topo *t = xzmalloc (sizeof (*t)); if (!(t->h = builtin_get_flux_handle (p))) err_exit ("flux_open"); t->rpc = flux_rpc (t->h, "resource-hwloc.topo", NULL, 0, 0); if (!t->rpc || (flux_rpc_get (t->rpc, NULL, &json_str) < 0)) err_exit ("flux_rpc"); if (!(t->o = Jfromstr (json_str)) || !Jget_str (t->o, "topology", &t->topo)) msg_exit ("failed to parse json topology"); return (t); }
static void test_txattrcreate (void) { Npfcall *fc, *fc2; if (!(fc = np_create_txattrcreate(1, "abc", 3, 4))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TXATTRCREATE, __FUNCTION__); assert (fc->u.txattrcreate.fid == fc2->u.txattrcreate.fid); assert (np_str9cmp (&fc->u.txattrcreate.name, &fc2->u.txattrcreate.name) == 0); assert (fc->u.txattrcreate.size == fc2->u.txattrcreate.size); assert (fc->u.txattrcreate.flag == fc2->u.txattrcreate.flag); free (fc); free (fc2); }
static void test_tmkdir (void) { Npfcall *fc, *fc2; if (!(fc = np_create_tmkdir (1, "abc", 2, 3))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TMKDIR, __FUNCTION__); assert (fc->u.tmkdir.fid == fc2->u.tmkdir.fid); assert (np_str9cmp (&fc->u.tmkdir.name, &fc2->u.tmkdir.name) == 0); assert (fc->u.tmkdir.mode == fc2->u.tmkdir.mode); assert (fc->u.tmkdir.gid == fc2->u.tmkdir.gid); free (fc); free (fc2); }
static void test_rmkdir (void) { Npfcall *fc, *fc2; struct p9_qid qid = { 1, 2, 3 }; if (!(fc = np_create_rmkdir (&qid))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RMKDIR, __FUNCTION__); assert (fc->u.rmkdir.qid.type == fc2->u.rmkdir.qid.type); assert (fc->u.rmkdir.qid.version == fc2->u.rmkdir.qid.version); assert (fc->u.rmkdir.qid.path == fc2->u.rmkdir.qid.path); free (fc); free (fc2); }
pctx_t proc_create (const char *root) { pctx_t ctx; if (!(ctx = malloc (sizeof (*ctx)))) msg_exit ("out of memory"); snprintf (ctx->pctx_root, sizeof (ctx->pctx_root), "%s/", root); ctx->pctx_path = ctx->pctx_root + strlen (ctx->pctx_root); ctx->pctx_pathlen = sizeof (ctx->pctx_root) - strlen (ctx->pctx_root); ctx->pctx_fp = NULL; ctx->pctx_dp = NULL; ctx->pctx_stat_pvt = NULL; ctx->pctx_magic = PCTX_MAGIC; return ctx; }
static void test_trenameat (void) { Npfcall *fc, *fc2; if (!(fc = np_create_trenameat (1, "abc", 2, "zyx"))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TRENAMEAT, __FUNCTION__); assert (fc->u.trenameat.olddirfid == fc2->u.trenameat.olddirfid); assert (np_str9cmp (&fc->u.trenameat.oldname, &fc2->u.trenameat.oldname) == 0); assert (fc->u.trenameat.newdirfid == fc2->u.trenameat.newdirfid); assert (np_str9cmp (&fc->u.trenameat.newname, &fc2->u.trenameat.newname) == 0); free (fc); free (fc2); }
static void test_rattach (void) { Npfcall *fc, *fc2; struct p9_qid qid = { 1, 2, 3 }; if (!(fc = np_create_rattach (&qid))) msg_exit ("out of memory in %s", __FUNCTION__); fc2 = _rcv_buf (fc, P9_RATTACH, __FUNCTION__); assert (fc->u.rattach.qid.type == fc2->u.rattach.qid.type); assert (fc->u.rattach.qid.version == fc2->u.rattach.qid.version); assert (fc->u.rattach.qid.path == fc2->u.rattach.qid.path); free (fc); free (fc2); }
static void test_tauth (void) { Npfcall *fc, *fc2; if (!(fc = np_create_tauth (1, "abc", "xyz", 4))) msg_exit ("out of memory in %s", __FUNCTION__); fc2 = _rcv_buf (fc, P9_TAUTH, __FUNCTION__); assert (fc->u.tauth.afid == fc2->u.tauth.afid); assert (np_str9cmp (&fc->u.tauth.uname, &fc2->u.tauth.uname) == 0); assert (np_str9cmp (&fc->u.tauth.aname, &fc2->u.tauth.aname) == 0); assert (fc->u.tauth.n_uname == fc2->u.tauth.n_uname); free (fc); free (fc2); }
static void test_rreaddir (void) { Npfcall *fc, *fc2; int n = 0, len = 256; struct p9_qid qid[3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }, qid2[3]; char *name[3] = { "abc", "def", "ghi" }, name2[3][128]; u64 offset; u8 type; if (!(fc = np_create_rreaddir (len))) msg_exit ("out of memory"); n += np_serialize_p9dirent (&qid[0], 0, 1, name[0], fc->u.rreaddir.data + n, len - n); n += np_serialize_p9dirent (&qid[1], 50, 2, name[1], fc->u.rreaddir.data + n, len - n); n += np_serialize_p9dirent (&qid[2], 100, 3, name[2], fc->u.rreaddir.data + n, len - n); assert (n < len); np_finalize_rreaddir (fc, n); fc2 = _rcv_buf (fc, P9_RREADDIR, __FUNCTION__); assert (fc->u.rreaddir.count == fc2->u.rreaddir.count); n = 0; n += np_deserialize_p9dirent (&qid2[0], &offset, &type, name2[0], 128, fc2->u.rreaddir.data + n, fc2->u.rreaddir.count - n); assert (offset == 0); assert (type == 1); assert (strcmp (name2[0], name[0]) == 0); n += np_deserialize_p9dirent (&qid2[1], &offset, &type, name2[1], 128, fc2->u.rreaddir.data + n, fc2->u.rreaddir.count - n); assert (offset == 50); assert (type == 2); assert (strcmp (name2[1], name[1]) == 0); n += np_deserialize_p9dirent (&qid2[2], &offset, &type, name2[2], 128, fc2->u.rreaddir.data + n, fc2->u.rreaddir.count - n); assert (offset == 100); assert (type == 3); assert (strcmp (name2[2], name[2]) == 0); assert (n == fc2->u.rreaddir.count); free (fc); free (fc2); }
static void test_rlcreate (void) { Npfcall *fc, *fc2; struct p9_qid qid = { 1, 2, 3 }; if (!(fc = np_create_rlcreate (&qid, 2))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RLCREATE, __FUNCTION__); assert (fc->u.rlcreate.qid.type == fc2->u.rlcreate.qid.type); assert (fc->u.rlcreate.qid.version == fc2->u.rlcreate.qid.version); assert (fc->u.rlcreate.qid.path == fc2->u.rlcreate.qid.path); assert (fc->u.rlcreate.iounit == fc2->u.rlcreate.iounit); free (fc); free (fc2); }
static void test_rgetlock (void) { Npfcall *fc, *fc2; if (!(fc = np_create_rgetlock (P9_LOCK_TYPE_WRLCK, 2, 3, 4, "xyz"))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RGETLOCK, __FUNCTION__); assert (fc->u.rgetlock.type == fc2->u.rgetlock.type); assert (fc->u.rgetlock.start == fc2->u.rgetlock.start); assert (fc->u.rgetlock.length == fc2->u.rgetlock.length); assert (fc->u.rgetlock.proc_id == fc2->u.rgetlock.proc_id); assert (np_str9cmp (&fc->u.rgetlock.client_id, &fc2->u.rgetlock.client_id) == 0); free (fc); free (fc2); }
static void test_tlcreate (void) { Npfcall *fc, *fc2; if (!(fc = np_create_tlcreate (1, "xyz", 3, 4, 5))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TLCREATE, __FUNCTION__); assert (fc->u.tlcreate.fid == fc2->u.tlcreate.fid); assert (np_str9cmp (&fc->u.tlcreate.name, &fc2->u.tlcreate.name) == 0); assert (fc->u.tlcreate.flags == fc2->u.tlcreate.flags); assert (fc->u.tlcreate.mode == fc2->u.tlcreate.mode); assert (fc->u.tlcreate.gid == fc2->u.tlcreate.gid); free (fc); free (fc2); }
static void test_tmknod (void) { Npfcall *fc, *fc2; if (!(fc = np_create_tmknod (1, "xyz", 3, 4, 5, 6))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TMKNOD, __FUNCTION__); assert (fc->u.tmknod.fid == fc2->u.tmknod.fid); assert (np_str9cmp (&fc->u.tmknod.name, &fc2->u.tmknod.name) == 0); assert (fc->u.tmknod.mode == fc2->u.tmknod.mode); assert (fc->u.tmknod.major == fc2->u.tmknod.major); assert (fc->u.tmknod.minor == fc2->u.tmknod.minor); assert (fc->u.tmknod.gid == fc2->u.tmknod.gid); free (fc); free (fc2); }
static void test_tlock (void) { Npfcall *fc, *fc2; if (!(fc = np_create_tlock (1, P9_LOCK_TYPE_UNLCK, 3, 4, 5, 6, "xyz"))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TLOCK, __FUNCTION__); assert (fc->u.tlock.fid == fc2->u.tlock.fid); assert (fc->u.tlock.type == fc2->u.tlock.type); assert (fc->u.tlock.flags == fc2->u.tlock.flags); assert (fc->u.tlock.start == fc2->u.tlock.start); assert (fc->u.tlock.length == fc2->u.tlock.length); assert (np_str9cmp (&fc->u.tlock.client_id, &fc2->u.tlock.client_id) == 0); free (fc); free (fc2); }
static int _prepare_stmt (lmt_db_t db, MYSQL_STMT **sp, const char *sql) { int retval = -1; MYSQL_STMT *s; if (!(s = mysql_stmt_init (db->conn))) msg_exit ("out of memory"); errno = 0; if (mysql_stmt_prepare (s, sql, strlen (sql))) { mysql_stmt_close (s); goto done; /* prepare fails if GRANT would not permit operation */ } *sp = s; retval = 0; done: return retval; }
static void test_rread (void) { Npfcall *fc, *fc2; u8 buf[128]; memset (buf, 0xf0, sizeof(buf)); if (!(fc = np_create_rread (sizeof (buf), buf))) msg_exit ("out of memory in %s", __FUNCTION__); np_set_rread_count (fc, sizeof (buf)); fc2 = _rcv_buf (fc, P9_RREAD, __FUNCTION__); assert (fc->u.rread.count == fc2->u.rread.count); assert (memcmp (fc->u.rread.data, fc2->u.rread.data, fc->u.rread.count) == 0); free (fc); free (fc2); }
static void test_twrite (void) { Npfcall *fc, *fc2; u8 buf[128]; memset (buf, 0x0f, sizeof(buf)); if (!(fc = np_create_twrite (1, 2, sizeof (buf), buf))) msg_exit ("out of memory in %s", __FUNCTION__); fc2 = _rcv_buf (fc, P9_TWRITE, __FUNCTION__); assert (fc->u.twrite.fid == fc2->u.twrite.fid); assert (fc->u.twrite.offset == fc2->u.twrite.offset); assert (fc->u.twrite.count == fc2->u.twrite.count); assert (memcmp (fc->u.twrite.data, fc2->u.twrite.data, fc->u.twrite.count) == 0); free (fc); free (fc2); }
/* Open/bind sockets for all addresses that can be associated with host:port, * and expand pollfd array (*fdsp) to contain the new file descriptors, * updating its size (*nfdsp) also. * Return the number of file descriptors added (can be 0). * This is a helper for diod_sock_listen (). */ static int _setup_one_inet (char *host, char *port, struct pollfd **fdsp, int *nfdsp) { struct addrinfo hints, *res = NULL, *r; int opt, error, fd; int count = 0; memset (&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((error = getaddrinfo (host, port, &hints, &res))) { msg ("getaddrinfo: %s:%s: %s", host, port, gai_strerror(error)); goto done; } if (res == NULL) { msg_exit ("listen address has no addrinfo: %s:%s\n", host, port); goto done; } for (r = res; r != NULL; r = r->ai_next) { if ((fd = socket (r->ai_family, r->ai_socktype, 0)) < 0) { err ("socket: %s:%s", host, port); continue; } opt = 1; (void)_enable_reuseaddr (fd); if (bind (fd, r->ai_addr, r->ai_addrlen) < 0) { err ("bind: %s:%s", host, port); close (fd); continue; } if (_poll_add (fdsp, nfdsp, fd) < 0) break; count++; } done: if (res) freeaddrinfo (res); return count; }
/* * ======== api_exit ======== */ void api_exit(void) { DBC_REQUIRE(api_c_refs > 0); api_c_refs--; if (api_c_refs == 0) { /* Release all modules initialized in api_init(). */ cod_exit(); dev_exit(); chnl_exit(); msg_exit(); io_exit(); strm_exit(); disp_exit(); node_exit(); proc_exit(); mgr_exit(); rmm_exit(); drv_exit(); } DBC_ENSURE(api_c_refs >= 0); }
static void test_rlerror (void) { Npfcall *fc, *fc2; char buf[STATIC_RLERROR_SIZE]; if (!(fc = np_create_rlerror (42))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RLERROR, __FUNCTION__); assert (fc->u.rlerror.ecode == fc2->u.rlerror.ecode); free (fc); free (fc2); fc = np_create_rlerror_static (42, buf, sizeof(buf)); fc2 = _rcv_buf (fc, P9_RLERROR, __FUNCTION__); assert (fc->u.rlerror.ecode == fc2->u.rlerror.ecode); free (fc2); }
static void test_rstatfs(void) { Npfcall *fc, *fc2; if (!(fc = np_create_rstatfs (1, 2, 3, 4, 5, 6, 7, 8, 9))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RSTATFS, __FUNCTION__); assert (fc->u.rstatfs.type == fc2->u.rstatfs.type); assert (fc->u.rstatfs.bsize == fc2->u.rstatfs.bsize); assert (fc->u.rstatfs.blocks == fc2->u.rstatfs.blocks); assert (fc->u.rstatfs.bfree == fc2->u.rstatfs.bfree); assert (fc->u.rstatfs.bavail== fc2->u.rstatfs.bavail); assert (fc->u.rstatfs.files == fc2->u.rstatfs.files); assert (fc->u.rstatfs.ffree == fc2->u.rstatfs.ffree); assert (fc->u.rstatfs.fsid == fc2->u.rstatfs.fsid); assert (fc->u.rstatfs.namelen == fc2->u.rstatfs.namelen); free (fc); free (fc2); }
static void test_tsetattr (void) { Npfcall *fc, *fc2; if (!(fc = np_create_tsetattr (1,2,3,4,5,6,7,8,9,10))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_TSETATTR, __FUNCTION__); assert (fc->u.tsetattr.fid == fc2->u.tsetattr.fid); assert (fc->u.tsetattr.valid == fc2->u.tsetattr.valid); assert (fc->u.tsetattr.mode == fc2->u.tsetattr.mode); assert (fc->u.tsetattr.uid == fc2->u.tsetattr.uid); assert (fc->u.tsetattr.gid == fc2->u.tsetattr.gid); assert (fc->u.tsetattr.size == fc2->u.tsetattr.size); assert (fc->u.tsetattr.atime_sec == fc2->u.tsetattr.atime_sec); assert (fc->u.tsetattr.atime_nsec == fc2->u.tsetattr.atime_nsec); assert (fc->u.tsetattr.mtime_sec == fc2->u.tsetattr.mtime_sec); assert (fc->u.tsetattr.mtime_nsec == fc2->u.tsetattr.mtime_nsec); free (fc); free (fc2); }
/* Timer pops every 1 ms, writing a new value to key. * After 10 calls, it calls kvs_unwatch(). * After 20 calls, it calls flux_reactor_stop(). * The kvs_unwatch_cb() counts the number of times it is called, should be 10. */ void test_unwatch (int argc, char **argv) { flux_t h; char *key; int count = 0; if (argc != 1) { fprintf (stderr, "Usage: unwatch key\n"); exit (1); } key = argv[0]; if (!(h = flux_open (NULL, 0))) err_exit ("flux_open"); if (kvs_watch_int (h, key, unwatch_watch_cb, &count) < 0) err_exit ("kvs_watch_int %s", key); if (flux_tmouthandler_add (h, 1, false, unwatch_timer_cb, key) < 0) err_exit ("flux_tmouthandler_add"); if (flux_reactor_start (h) < 0) err_exit ("flux_reactor_start"); if (count != 10) msg_exit ("watch called %d times (should be 10)", count); flux_close (h); }
static void test_rgetattr (void) { Npfcall *fc, *fc2; struct p9_qid qid = { 1, 2, 3 }; if (!(fc = np_create_rgetattr (1, &qid, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RGETATTR, __FUNCTION__); assert (fc->u.rgetattr.valid == fc2->u.rgetattr.valid); assert (fc->u.rgetattr.qid.type == fc2->u.rgetattr.qid.type); assert (fc->u.rgetattr.qid.version == fc2->u.rgetattr.qid.version); assert (fc->u.rgetattr.qid.path == fc2->u.rgetattr.qid.path); assert (fc->u.rgetattr.mode == fc2->u.rgetattr.mode); assert (fc->u.rgetattr.uid == fc2->u.rgetattr.uid); assert (fc->u.rgetattr.gid == fc2->u.rgetattr.gid); assert (fc->u.rgetattr.nlink == fc2->u.rgetattr.nlink); assert (fc->u.rgetattr.rdev == fc2->u.rgetattr.rdev); assert (fc->u.rgetattr.size == fc2->u.rgetattr.size); assert (fc->u.rgetattr.blksize == fc2->u.rgetattr.blksize); assert (fc->u.rgetattr.blocks == fc2->u.rgetattr.blocks); assert (fc->u.rgetattr.atime_sec == fc2->u.rgetattr.atime_sec); assert (fc->u.rgetattr.atime_nsec == fc2->u.rgetattr.atime_nsec); assert (fc->u.rgetattr.mtime_sec == fc2->u.rgetattr.mtime_sec); assert (fc->u.rgetattr.mtime_nsec == fc2->u.rgetattr.mtime_nsec); assert (fc->u.rgetattr.ctime_sec == fc2->u.rgetattr.ctime_sec); assert (fc->u.rgetattr.ctime_nsec == fc2->u.rgetattr.ctime_nsec); assert (fc->u.rgetattr.btime_sec == fc2->u.rgetattr.btime_sec); assert (fc->u.rgetattr.btime_nsec == fc2->u.rgetattr.btime_nsec); assert (fc->u.rgetattr.gen == fc2->u.rgetattr.gen); assert (fc->u.rgetattr.data_version == fc2->u.rgetattr.data_version); free (fc); free (fc2); }
int lmt_db_list (char *user, char *pass, List *lp) { char *host = lmt_conf_get_db_host (); int port = lmt_conf_get_db_port (); List l = list_create ((ListDelF)free); MYSQL *conn = NULL; MYSQL_RES *res = NULL; MYSQL_ROW row; int retval = -1; if (!(conn = mysql_init (NULL))) msg_exit ("out of memory"); if (!mysql_real_connect (conn, host, user, pass, NULL, port, NULL, 0)) { if (lmt_conf_get_db_debug ()) msg ("lmt_db_list: %s", mysql_error (conn)); goto done; } if (!(res = mysql_list_dbs (conn, "filesystem_%"))) { if (lmt_conf_get_db_debug ()) msg ("lmt_db_list: unable to list lmt databases"); goto done; } while ((row = mysql_fetch_row (res))) list_append (l, xstrdup (row[0])); *lp = l; retval = 0; done: if (res) mysql_free_result (res); if (conn) mysql_close (conn); if (retval < 0) list_destroy (l); return retval; }
int opt_vscanf (Opt o, const char *fmt, va_list ap) { ListIterator itr; char *item; int ret = 0; NP_ASSERT (o->magic == OPT_MAGIC); if (!(itr = list_iterator_create (o->list))) msg_exit ("out of memory"); while ((item = list_next (itr))) { va_list vacpy; va_copy (vacpy, ap); ret = vsscanf (item, fmt, vacpy); va_end (vacpy); if (ret > 0) break; } list_iterator_destroy (itr); return ret; }
static void change_fsid (uid_t olduid, gid_t oldgid, uid_t uid, gid_t gid) { uid_t u; gid_t g; if (uid != olduid) { u = setfsuid (uid); if (u == -1) err ("setfsuid"); else if (u != olduid) msg ("setfsuid returned %d (wanted %d)", u, olduid); } if (gid != oldgid) { g = setfsgid (gid); if (g == -1) err ("setfsgid"); else if (g != oldgid) msg ("setfsgid returned %d (wanted %d)", g, oldgid); } if (!check_fsid (uid, gid)) msg_exit ("setfsuid/setfsgid failed"); msg ("fsid changed to %d:%d", uid, gid); }
int main (int argc, char *argv[]) { char *server = NULL; int msize = 65536; uid_t uid = geteuid (); int topt = 0; Npcfsys *fs = NULL; Npcfid *fid, *afid, *root; int c, fd; char buf[80], *host, *p; hostlist_t hl; hostlist_iterator_t itr; int lopt = 0; diod_log_init (argv[0]); opterr = 0; while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) { switch (c) { case 's': /* --server HOST[:PORT] or /path/to/socket */ server = optarg; break; case 'm': /* --msize SIZE */ msize = strtoul (optarg, NULL, 10); break; case 'u': /* --uid UID */ uid = strtoul (optarg, NULL, 10); break; case 't': /* --timeout SECS */ topt = strtoul (optarg, NULL, 10); break; case 'l': /* --long */ lopt = 1; break; default: usage (); } } if (signal (SIGPIPE, SIG_IGN) == SIG_ERR) err_exit ("signal"); if (signal (SIGALRM, sigalarm) == SIG_ERR) err_exit ("signal"); if (topt > 0) alarm (topt); if ((fd = diod_sock_connect (server, 0)) < 0) exit (1); if (!(fs = npc_start (fd, fd, msize, 0))) errn_exit (np_rerror (), "error negotiating protocol with server"); if (!(afid = npc_auth (fs, "ctl", uid, diod_auth)) && np_rerror () != 0) errn_exit (np_rerror (), "error authenticating to server"); if (!(root = npc_attach (fs, afid, "ctl", uid))) errn_exit (np_rerror (), "error attaching to aname=ctl"); if (!(fid = npc_open_bypath (root, "connections", O_RDONLY))) errn_exit (np_rerror (), "open connections"); if (!(hl = hostlist_create (NULL))) err_exit ("hostlist_create"); while (npc_gets (fid, buf, sizeof(buf))) { if ((p = strchr (buf, ' '))) *p = '\0'; if (!lopt && (p = strchr (buf, '.'))) *p = '\0'; if (!hostlist_push_host (hl, buf)) err_exit ("hostlist_push_host"); } hostlist_uniq (hl); if (lopt) { if (!(itr = hostlist_iterator_create (hl))) err_exit ("hostlist_iterator_create"); while ((host = hostlist_next (itr))) printf ("%s\n", host); hostlist_iterator_destroy (itr); } else { char s[1024]; if (hostlist_ranged_string (hl, sizeof (s), s) < 0) msg_exit ("hostlist output would be too long (use -l)"); printf ("%s\n", s); } hostlist_destroy (hl); if (npc_clunk (fid) < 0) errn_exit (np_rerror (), "clunk connections"); if (npc_clunk (root) < 0) errn_exit (np_rerror (), "error clunking ctl"); if (npc_clunk (afid) < 0) errn_exit (np_rerror (), "error clunking afid"); npc_finish (fs); exit(0); }
static void sigalarm (int arg) { msg_exit ("timed out"); }