Skip to content

Commit

Permalink
Fix a few problems found in testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Mar 16, 2010
1 parent d9d5922 commit a2217f4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
@@ -0,0 +1,11 @@
2010-03-16 Jim Garlick <garlick@llnl.gov>

* diod/diod.c, diodctl/diodctl.c : Daemonize before listening or
daemon () closes our ports for us. Remove log complaints about chdir
to rundir.

* diodctl/ops.c : Include a log message for all attach failures.

2010-03-16 Jim Garlick <garlick@llnl.gov>

* : tag 1.0-pre1
4 changes: 4 additions & 0 deletions README
Expand Up @@ -13,3 +13,7 @@ TODO
- mount generates attach + stat / - can we cache stat / result to avoid
touching all the file system at mount time (e.g. when doing it at the
beginning of every cluster job)? If just one fs is down, everything hangs.
- diodmount should umount control file system when it aborts for other reasons
- init scripts 'restart' fails to start server if it is not already running
- init scripts should create rundir if it doesn't exist
- diodctl dynamic allocation of ports needs to use all server interfaces
13 changes: 5 additions & 8 deletions diod/diod.c
Expand Up @@ -223,6 +223,9 @@ main(int argc, char **argv)
if (geteuid () == 0)
_setrlimit ();

if (!diod_conf_get_foreground ())
_daemonize ();

/* drop privileges, unless running for multiple users */
if (diod_conf_get_runasuid (&uid))
diod_become_user (NULL, uid, 1);
Expand All @@ -240,9 +243,6 @@ main(int argc, char **argv)
msg_exit ("failed to set up listen ports");
}

if (!diod_conf_get_foreground ())
_daemonize ();

diod_register_ops (srv);
diod_sock_accept_loop (srv, fds, nfds, diod_conf_get_tcpwrappers ());
/*NOTREACHED*/
Expand All @@ -257,11 +257,8 @@ _daemonize (void)

snprintf (rdir, sizeof(rdir), "%s/run/diod", X_LOCALSTATEDIR);

if (chdir (rdir) < 0) {
err ("warning: chdir %s", rdir);
if (chdir ("/") < 0)
err_exit ("chdir /");
}
if (chdir (rdir) < 0 && chdir ("/") < 0)
err_exit ("chdir /");
if (daemon (1, 0) < 0)
err_exit ("daemon");
diod_log_to_syslog();
Expand Down
13 changes: 5 additions & 8 deletions diodctl/diodctl.c
Expand Up @@ -212,13 +212,14 @@ main(int argc, char **argv)
msg_exit ("must run as root");
_setrlimit ();

if (!diod_conf_get_foreground ())
_daemonize ();

srv = np_srv_create (diod_conf_get_nwthreads ());
if (!srv)
msg_exit ("out of memory");
if (!diod_sock_listen_list (&fds, &nfds, diod_conf_get_diodctllisten ()))
msg_exit ("failed to set up listen ports");
if (!diod_conf_get_foreground ())
_daemonize ();

/* FIXME: temp file created by diod_conf_mkconfig () needs cleanup */
diodctl_serv_init (diod_conf_mkconfig ());
Expand All @@ -236,12 +237,8 @@ _daemonize (void)

snprintf (rdir, sizeof(rdir), "%s/run/diod", X_LOCALSTATEDIR);

if (chdir (rdir) < 0) {
err ("warning: chdir %s", rdir);
if (chdir ("/") < 0)
err_exit ("chdir /");
}

if (chdir (rdir) < 0 && chdir ("/") < 0)
err_exit ("chdir /");
if (daemon (1, 0) < 0)
err_exit ("daemon");
diod_log_to_syslog();
Expand Down
13 changes: 10 additions & 3 deletions diodctl/ops.c
Expand Up @@ -81,10 +81,12 @@ _ctl_attach (Npfid *fid, Npfid *nafid, Npstr *uname, Npstr *aname)

if (nafid) { /* 9P Tauth not supported */
np_werror (Enoauth, EIO);
msg ("diodctl_attach: 9P Tauth is not supported");
goto done;
}
if (np_strcmp (aname, "/diodctl") != 0) {
np_uerror (EPERM);
msg ("diodctl_attach: mount attempt for aname other than /diodctl");
goto done;
}
/* Munge authentication involves the upool and trans layers:
Expand All @@ -99,23 +101,28 @@ _ctl_attach (Npfid *fid, Npfid *nafid, Npstr *uname, Npstr *aname)
} else {
if (diod_trans_get_authuser (fid->conn->trans, &auid) < 0) {
np_uerror (EPERM);
msg ("diodctl_attach: attach rejected from unauthenticated user");
goto done;
}
if (auid != 0 && auid != fid->user->uid) {
np_uerror (EPERM);
msg ("diodctl_attach: attach rejected from unauthenticated user");
goto done;
}
}
}
if (!npfile_checkperm (root, fid->user, 4)) {
np_uerror (EPERM);
msg ("diodctl_attach: root file mode denies access for user");
goto done;
}
if (!(f = npfile_fidalloc (root, fid))) {
msg ("diodctl_attach: out of memory");
np_uerror (ENOMEM);
goto done;
}
if (!(ret = np_create_rattach (&root->qid))) {
msg ("diodctl_attach: out of memory");
np_uerror (ENOMEM);
goto done;
}
Expand Down Expand Up @@ -185,12 +192,12 @@ static int
_ctl_write (Npfilefid* file, u64 offset, u32 count, u8* data, Npreq *req)
{
Npfid *fid = file->fid;
char *ip = diod_trans_get_ip (fid->conn->trans);
int ret = 0;

if (!diod_conf_get_allowprivate ())
if (!diod_conf_get_allowprivate ()) {
np_uerror (EPERM);
else if (diodctl_serv_create (fid->user, ip))
msg ("diodctl_write: diodctl is not configured for private mounts");
} else if (diodctl_serv_create (fid->user))
ret = count;
return ret;
}
Expand Down

0 comments on commit a2217f4

Please sign in to comment.