int chpst_main(int argc ATTRIBUTE_UNUSED, char **argv) { INIT_G(); if (applet_name[3] == 'd') envdir(argc, argv); if (applet_name[1] == 'o') softlimit(argc, argv); if (applet_name[0] == 's') setuidgid(argc, argv); if (applet_name[0] == 'e') envuidgid(argc, argv); // otherwise we are chpst { char *m,*d,*o,*p,*f,*c,*r,*t,*n; getopt32(argv, "+u:U:e:m:d:o:p:f:c:r:t:/:n:vP012", &set_user,&env_user,&env_dir, &m,&d,&o,&p,&f,&c,&r,&t,&root,&n); // if (option_mask32 & 0x1) // -u // if (option_mask32 & 0x2) // -U // if (option_mask32 & 0x4) // -e if (option_mask32 & 0x8) limits = limitl = limita = limitd = xatoul(m); // -m if (option_mask32 & 0x10) limitd = xatoul(d); // -d if (option_mask32 & 0x20) limito = xatoul(o); // -o if (option_mask32 & 0x40) limitp = xatoul(p); // -p if (option_mask32 & 0x80) limitf = xatoul(f); // -f if (option_mask32 & 0x100) limitc = xatoul(c); // -c if (option_mask32 & 0x200) limitr = xatoul(r); // -r if (option_mask32 & 0x400) limitt = xatoul(t); // -t // if (option_mask32 & 0x800) // -/ if (option_mask32 & 0x1000) nicelvl = xatoi(n); // -n // The below consts should match #defines at top! //if (option_mask32 & 0x2000) OPT_verbose = 1; // -v //if (option_mask32 & 0x4000) OPT_pgrp = 1; // -P //if (option_mask32 & 0x8000) OPT_nostdin = 1; // -0 //if (option_mask32 & 0x10000) OPT_nostdout = 1; // -1 //if (option_mask32 & 0x20000) OPT_nostderr = 1; // -2 } argv += optind; if (!argv || !*argv) bb_show_usage(); if (OPT_pgrp) setsid(); if (env_dir) edir(env_dir); if (root) { xchdir(root); xchroot("."); } slimit(); if (nicelvl) { errno = 0; if (nice(nicelvl) == -1) bb_perror_msg_and_die("nice"); } if (env_user) euidgid(env_user); if (set_user) suidgid(set_user); if (OPT_nostdin) close(0); if (OPT_nostdout) close(1); if (OPT_nostderr) close(2); BB_EXECVP(argv[0], argv); bb_perror_msg_and_die("exec %s", argv[0]); }
void envdir(int argc, const char *const *argv) { const char *dir; if (! (dir =*++argv)) envdir_usage(); if (! *++argv) envdir_usage(); edir(dir); pathexec(argv); fatal2("unable to run", *argv); }
static void envdir(int argc, char **argv) { const char *dir; dir = *++argv; if (!dir) bb_show_usage(); if (!*++argv) bb_show_usage(); edir(dir); BB_EXECVP(argv[0], argv); bb_perror_msg_and_die("exec %s", argv[0]); }
/** * This method fills in the adjacentState reference with * the state for a given adjacency. * * @param index Index of adjacency * @param adjacency State of adjacency is copied here * @param goal Goal state * * @return True if this is a valid adjacency. */ bool WaypointState::getAdjacency(int index, WaypointState& adjacency, const WaypointGoalState& goal) const { Vector2 src, dst, p1, p2, movementVector, next; float p, cp1, cp2; // If this edge on waypoint is not passable, forget it. const WaypointSet * pAdjSet = pWaypoint_->adjacentWaypointSet(index); if (pWaypoint_->adjacentWaypoint(index) == NULL && pAdjSet == NULL) return false; // We need 2d vectors for intersection tests. src.x = position_.x; src.y = position_.z; dst.x = goal.position_.x; dst.y = goal.position_.z; movementVector = dst - src; p1 = pWaypoint_->vertexPosition(index); p2 = pWaypoint_->vertexPosition((index + 1) % pWaypoint_->vertexCount()); // move the pts towards each other if we have extra radius if (goal.extraRadius() > 0.f) { const float ger = goal.extraRadius(); Vector2 edir( p2 - p1 ); const float elen = edir.length(); // for now can only pass edges that are long enough // (need to only move in conditionally, e.g. if adj to black) if (elen < ger * 2.f) return false; edir *= ger / elen; p1 += edir; p2 -= edir; } cp1 = movementVector.crossProduct(p1 - src); cp2 = movementVector.crossProduct(p2 - src); // If our desired path takes us through this line segment, // find the intersection and use it. Otherwise use the // vertex whose crossproduct is closest to zero. if(cp1 > 0.0f && cp2 < 0.0f) { LineEq moveLine(src, dst, true); LineEq edgeLine(p1, p2, true); p = moveLine.intersect(edgeLine); next = moveLine.param(p); } else if(fabs(cp1) < fabs(cp2)) { next = p1; } else { next = p2; } adjacency.pWPSet_ = (pAdjSet == NULL) ? pWPSet_ : pAdjSet; adjacency.waypointID_ = pWaypoint_->adjacentID(index); adjacency.pWaypoint_ = pWaypoint_->adjacentWaypoint(index); adjacency.position_.x = next.x; adjacency.position_.y = position_.y; adjacency.position_.z = next.y; adjacency.distanceFromParent_ = (position_ - adjacency.position_).length(); return true; }
int main(int argc, const char **argv) { int opt; int i; unsigned long ul; progname =argv[0]; for (i =str_len(progname); i; --i) if (progname[i -1] == '/') { progname +=i; break; } if (progname[0] == 'd') ++progname; /* argv[0] */ if (str_equal(progname, "setuidgid")) setuidgid(argc, argv); if (str_equal(progname, "envuidgid")) envuidgid(argc, argv); if (str_equal(progname, "envdir")) envdir(argc, argv); if (str_equal(progname, "pgrphack")) pgrphack(argc, argv); if (str_equal(progname, "setlock")) setlock(argc, argv); if (str_equal(progname, "softlimit")) softlimit(argc, argv); while ((opt =getopt(argc, argv, "u:U:b:e:m:d:o:p:f:c:r:t:/:n:l:L:vP012V")) != opteof) switch(opt) { case 'u': set_user =(char*)optarg; break; case 'U': env_user =(char*)optarg; break; case 'b': argv0 =(char*)optarg; break; case 'e': env_dir =optarg; break; case 'm': if (optarg[scan_ulong(optarg, &ul)]) usage(); limits =limitl =limita =limitd =ul; break; case 'd': if (optarg[scan_ulong(optarg, &ul)]) usage(); limitd =ul; break; case 'o': if (optarg[scan_ulong(optarg, &ul)]) usage(); limito =ul; break; case 'p': if (optarg[scan_ulong(optarg, &ul)]) usage(); limitp =ul; break; case 'f': if (optarg[scan_ulong(optarg, &ul)]) usage(); limitf =ul; break; case 'c': if (optarg[scan_ulong(optarg, &ul)]) usage(); limitc =ul; break; case 'r': if (optarg[scan_ulong(optarg, &ul)]) usage(); limitr =ul; break; case 't': if (optarg[scan_ulong(optarg, &ul)]) usage(); limitt =ul; break; case '/': root =optarg; break; case 'n': switch (*optarg) { case '-': if (optarg[scan_ulong(++optarg, &ul)]) usage(); nicelvl =ul; nicelvl *=-1; break; case '+': ++optarg; default: if (optarg[scan_ulong(optarg, &ul)]) usage(); nicelvl =ul; break; } break; case 'l': if (lock) usage(); lock =optarg; lockdelay =1; break; case 'L': if (lock) usage(); lock =optarg; lockdelay =0; break; case 'v': verbose =1; break; case 'P': pgrp =1; break; case '0': nostdin =1; break; case '1': nostdout =1; break; case '2': nostderr =1; break; case 'V': strerr_warn1("$Id: f279d44141c981dd7535a12260efcf1ef7beed26 $", 0); case '?': usage(); } argv +=optind; if (! argv || ! *argv) usage(); if (pgrp) setsid(); if (env_dir) edir(env_dir); if (root) { if (chdir(root) == -1) fatal2("unable to change directory", root); if (chroot(".") == -1) fatal("unable to change root directory"); } if (nicelvl) { errno =0; if (nice(nicelvl) == -1) if (errno) fatal("unable to set nice level"); } if (env_user) euidgid(env_user, 1); if (set_user) suidgid(set_user, 1); if (lock) slock(lock, lockdelay, 0); if (nostdin) if (close(0) == -1) fatal("unable to close stdin"); if (nostdout) if (close(1) == -1) fatal("unable to close stdout"); if (nostderr) if (close(2) == -1) fatal("unable to close stderr"); slimit(); progname =*argv; if (argv0) *argv =argv0; pathexec_env_run(progname, argv); fatal2("unable to run", *argv); return(0); }