#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <pwd.h>
+#include <grp.h>
#include <netinet/in.h>
#include <signal.h>
#include <pthread.h>
int interval = 0;
f64 *vector_ratep, *rx_ratep, *sig_error_ratep;
pid_t *vpp_pidp;
+ svmdb_map_args_t _ma, *ma= &_ma;
+ int uid, gid, rv;
+ struct passwd _pw, *pw;
+ struct group _grp, *grp;
+ char *s, buf[128];
unformat_init_command_line (&input, argv);
+ uid = geteuid();
+ gid = getegid();
+
while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (&input, "chroot %s", &chroot_path_u8))
}
else if (unformat (&input, "interval %d", &interval))
;
+ else if (unformat (&input, "uid %d", &uid))
+ ;
+ else if (unformat (&input, "gid %d", &gid))
+ ;
+ else if (unformat (&input, "uid %s", &s))
+ {
+ /* lookup the username */
+ pw = NULL;
+ rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
+ if (rv < 0)
+ {
+ fformat (stderr, "cannot fetch username %s", s);
+ exit (1);
+ }
+ if (pw == NULL)
+ {
+ fformat (stderr, "username %s does not exist", s);
+ exit (1);
+ }
+ vec_free (s);
+ uid = pw->pw_uid;
+ }
+ else if (unformat (&input, "gid %s", &s))
+ {
+ /* lookup the group name */
+ grp = NULL;
+ rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
+ if (rv != 0)
+ {
+ fformat (stderr, "cannot fetch group %s", s);
+ exit (1);
+ }
+ if (grp == NULL)
+ {
+ fformat (stderr, "group %s does not exist", s);
+ exit (1);
+ }
+ vec_free (s);
+ gid = grp->gr_gid;
+ }
else
{
fformat (stderr,
setup_signal_handlers ();
- c = svmdb_map_chroot (chroot_path);
+ memset (ma, 0, sizeof (*ma));
+ ma->root_path = chroot_path;
+ ma->uid = uid;
+ ma->gid = gid;
+
+ c = svmdb_map (ma);
vpp_pidp =
svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC, "vpp_pid");
do
{
- /* Once vpp exits, the svm db region will be recreated... */
- if (*vpp_pidp == 0 || kill (*vpp_pidp, 0) < 0)
+ /*
+ * Once vpp exits, the svm db region will be recreated...
+ * Can't use kill (*vpp_pidp, 0) if running as non-root /
+ * accessing the shared-VM database via group perms.
+ */
+ if (*vpp_pidp == 0)
{
fformat (stdout, "vpp not running\n");
exit (1);