int main (int argc, char *argv[]) { Npsrv *srv; Npconn *conn; Nptrans *trans; int flags = SRV_FLAGS_DEBUG_9PTRACE | SRV_FLAGS_DEBUG_USER; diod_log_init (argv[0]); diod_conf_init (); if (!(srv = np_srv_create (16, flags))) errn_exit (np_rerror (), "out of memory"); srv->logmsg = diod_log_msg; srv->attach = myattach; srv->clunk = myclunk; /* create one connection */ if (!(trans = ttrans_create ())) err_exit ("ttrans_create"); if (!(conn = np_conn_create (srv, trans, "loopback"))) msg_exit ("np_conn_create failure"); _send_tversion (trans); _send_tauth (trans); _send_tattach (trans, 0, 0); _send_tattach (trans, 0, 1); _send_tattach (trans, 1, 2); _send_tattach (trans, 1, 3); _send_tattach (trans, 0, 4); _send_tclunk (trans, 4); _send_tclunk (trans, 3); _send_tclunk (trans, 2); _send_tclunk (trans, 1); _send_tclunk (trans, 0); ttrans_rpc (trans, NULL, NULL); /* signifies EOF to reader */ /* wait for exactly one connect/disconnect */ np_srv_wait_conncount (srv, 1); sleep(1); /* racy here - conn reader needs time to process EOF */ np_srv_destroy (srv); diod_conf_fini (); diod_log_fini (); exit (0); }
int main(int argc, char **argv) { int c; char *copt = NULL; srvmode_t mode = SRV_NORMAL; int rfdno = -1, wfdno = -1; diod_log_init (argv[0]); diod_conf_init (); /* config file overrides defaults */ opterr = 0; while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) { switch (c) { case 'c': /* --config-file PATH */ copt = optarg; break; default: break; } } diod_conf_init_config_file (copt); /* Command line overrides config file. */ optind = 0; opterr = 0; while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) { switch (c) { case 'f': /* --foreground */ diod_conf_set_foreground (1); break; case 'r': /* --rfdno */ mode = SRV_FILEDES; rfdno = strtoul (optarg, NULL, 10); break; case 'w': /* --wfdno */ mode = SRV_FILEDES; wfdno = strtoul (optarg, NULL, 10); break; case 'd': /* --debug MASK */ diod_conf_set_debuglevel (strtoul (optarg, NULL, 0)); break; case 'l': /* --listen HOST:PORT or /path/to/socket */ if (!diod_conf_opt_listen ()) diod_conf_clr_listen (); if (!strchr (optarg, ':') && optarg[0] != '/') usage (); diod_conf_add_listen (optarg); break; case 't': /* --nwthreads INT */ diod_conf_set_nwthreads (strtoul (optarg, NULL, 10)); break; case 'c': /* --config-file PATH */ break; case 'e': /* --export PATH */ if (!diod_conf_opt_exports ()) diod_conf_clr_exports (); diod_conf_add_exports (optarg); break; case 'E': /* --export-all */ diod_conf_set_exportall (1); break; case 'o': /* --export-ops opt,[opt,...] */ diod_conf_set_exportopts (optarg); break; case 'n': /* --no-auth */ diod_conf_set_auth_required (0); break; case 'p': /* --statfs-passthru */ diod_conf_set_statfs_passthru (0); break; case 'N': /* --no-userdb */ diod_conf_set_userdb (0); break; case 'S': /* --allsquash */ diod_conf_set_allsquash (1); break; case 'U': /* --squashuser USER */ diod_conf_set_squashuser (optarg); break; case 'u': { /* --runas-uid UID */ uid_t uid; char *end; errno = 0; uid = strtoul (optarg, &end, 10); if (errno != 0) err_exit ("error parsing --runas-uid argument"); if (*end != '\0') msg_exit ("error parsing --runas-uid argument"); diod_conf_set_runasuid (uid); break; } case 's': /* --socktest */ mode = SRV_SOCKTEST; break; case 'L': /* --logdest DEST */ diod_conf_set_logdest (optarg); diod_log_set_dest (optarg); break; default: usage(); } } if (optind < argc) usage(); if (diod_conf_opt_runasuid () && diod_conf_get_allsquash ()) msg_exit ("--runas-uid and allsquash cannot be used together"); if (mode == SRV_FILEDES && (rfdno == -1 || wfdno == -1)) msg_exit ("--rfdno,wfdno must be used together"); diod_conf_validate_exports (); if (geteuid () == 0) _setrlimit (); _service_run (mode, rfdno, wfdno); diod_conf_fini (); diod_log_fini (); exit (0); }