| 2357 | | SAND_COPY_KERNEL("exec"); |
| 2358 | | SAND_COPY_KERNEL("fork"); |
| 2359 | | SAND_COPY_KERNEL("exit!"); |
| 2360 | | SAND_COPY_KERNEL("system"); |
| 2361 | | SAND_COPY_KERNEL("sleep"); |
| 2362 | | |
| 2363 | | /* |
| 2364 | | rb_mProcess = rb_define_module("Process"); |
| 2365 | | |
| 2366 | | #if !defined(_WIN32) && !defined(DJGPP) |
| 2367 | | #ifdef WNOHANG |
| 2368 | | rb_define_const(rb_mProcess, "WNOHANG", INT2FIX(WNOHANG)); |
| 2369 | | #else |
| 2370 | | rb_define_const(rb_mProcess, "WNOHANG", INT2FIX(0)); |
| 2371 | | #endif |
| 2372 | | #ifdef WUNTRACED |
| 2373 | | rb_define_const(rb_mProcess, "WUNTRACED", INT2FIX(WUNTRACED)); |
| 2374 | | #else |
| 2375 | | rb_define_const(rb_mProcess, "WUNTRACED", INT2FIX(0)); |
| 2376 | | #endif |
| 2377 | | #endif |
| 2378 | | |
| 2379 | | rb_define_singleton_method(rb_mProcess, "fork", rb_f_fork, 0); |
| 2380 | | rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1); |
| 2381 | | rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1); |
| 2382 | | rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1); |
| 2383 | | |
| 2384 | | rb_define_module_function(rb_mProcess, "kill", rb_f_kill, -1); |
| 2385 | | rb_define_module_function(rb_mProcess, "wait", proc_wait, -1); |
| 2386 | | rb_define_module_function(rb_mProcess, "wait2", proc_wait2, -1); |
| 2387 | | rb_define_module_function(rb_mProcess, "waitpid", proc_wait, -1); |
| 2388 | | rb_define_module_function(rb_mProcess, "waitpid2", proc_wait2, -1); |
| 2389 | | rb_define_module_function(rb_mProcess, "waitall", proc_waitall, 0); |
| 2390 | | rb_define_module_function(rb_mProcess, "detach", proc_detach, 1); |
| 2391 | | |
| 2392 | | rb_cProcStatus = rb_define_class_under(rb_mProcess, "Status", rb_cObject); |
| 2393 | | rb_undef_method(CLASS_OF(rb_cProcStatus), "new"); |
| 2394 | | |
| 2395 | | rb_define_method(rb_cProcStatus, "==", pst_equal, 1); |
| 2396 | | rb_define_method(rb_cProcStatus, "&", pst_bitand, 1); |
| 2397 | | rb_define_method(rb_cProcStatus, ">>", pst_rshift, 1); |
| 2398 | | rb_define_method(rb_cProcStatus, "to_i", pst_to_i, 0); |
| 2399 | | rb_define_method(rb_cProcStatus, "to_int", pst_to_i, 0); |
| 2400 | | rb_define_method(rb_cProcStatus, "to_s", pst_to_s, 0); |
| 2401 | | rb_define_method(rb_cProcStatus, "inspect", pst_inspect, 0); |
| 2402 | | |
| 2403 | | rb_define_method(rb_cProcStatus, "pid", pst_pid, 0); |
| 2404 | | |
| 2405 | | rb_define_method(rb_cProcStatus, "stopped?", pst_wifstopped, 0); |
| 2406 | | rb_define_method(rb_cProcStatus, "stopsig", pst_wstopsig, 0); |
| 2407 | | rb_define_method(rb_cProcStatus, "signaled?", pst_wifsignaled, 0); |
| 2408 | | rb_define_method(rb_cProcStatus, "termsig", pst_wtermsig, 0); |
| 2409 | | rb_define_method(rb_cProcStatus, "exited?", pst_wifexited, 0); |
| 2410 | | rb_define_method(rb_cProcStatus, "exitstatus", pst_wexitstatus, 0); |
| 2411 | | rb_define_method(rb_cProcStatus, "success?", pst_success_p, 0); |
| 2412 | | rb_define_method(rb_cProcStatus, "coredump?", pst_wcoredump, 0); |
| 2413 | | |
| 2414 | | rb_define_module_function(rb_mProcess, "pid", get_pid, 0); |
| 2415 | | rb_define_module_function(rb_mProcess, "ppid", get_ppid, 0); |
| 2416 | | |
| 2417 | | rb_define_module_function(rb_mProcess, "getpgrp", proc_getpgrp, 0); |
| 2418 | | rb_define_module_function(rb_mProcess, "setpgrp", proc_setpgrp, 0); |
| 2419 | | rb_define_module_function(rb_mProcess, "getpgid", proc_getpgid, 1); |
| 2420 | | rb_define_module_function(rb_mProcess, "setpgid", proc_setpgid, 2); |
| 2421 | | |
| 2422 | | rb_define_module_function(rb_mProcess, "setsid", proc_setsid, 0); |
| 2423 | | |
| 2424 | | rb_define_module_function(rb_mProcess, "getpriority", proc_getpriority, 2); |
| 2425 | | rb_define_module_function(rb_mProcess, "setpriority", proc_setpriority, 3); |
| 2426 | | |
| 2427 | | #ifdef HAVE_GETPRIORITY |
| 2428 | | rb_define_const(rb_mProcess, "PRIO_PROCESS", INT2FIX(PRIO_PROCESS)); |
| 2429 | | rb_define_const(rb_mProcess, "PRIO_PGRP", INT2FIX(PRIO_PGRP)); |
| 2430 | | rb_define_const(rb_mProcess, "PRIO_USER", INT2FIX(PRIO_USER)); |
| 2431 | | #endif |
| 2432 | | |
| 2433 | | rb_define_module_function(rb_mProcess, "getrlimit", proc_getrlimit, 1); |
| 2434 | | rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1); |
| 2435 | | #ifdef RLIM2NUM |
| 2436 | | #ifdef RLIM_INFINITY |
| 2437 | | rb_define_const(rb_mProcess, "RLIM_INFINITY", RLIM2NUM(RLIM_INFINITY)); |
| 2438 | | #endif |
| 2439 | | #ifdef RLIM_SAVED_MAX |
| 2440 | | rb_define_const(rb_mProcess, "RLIM_SAVED_MAX", RLIM2NUM(RLIM_SAVED_MAX)); |
| 2441 | | #endif |
| 2442 | | #ifdef RLIM_SAVED_CUR |
| 2443 | | rb_define_const(rb_mProcess, "RLIM_SAVED_CUR", RLIM2NUM(RLIM_SAVED_CUR)); |
| 2444 | | #endif |
| 2445 | | #ifdef RLIMIT_CORE |
| 2446 | | rb_define_const(rb_mProcess, "RLIMIT_CORE", INT2FIX(RLIMIT_CORE)); |
| 2447 | | #endif |
| 2448 | | #ifdef RLIMIT_CPU |
| 2449 | | rb_define_const(rb_mProcess, "RLIMIT_CPU", INT2FIX(RLIMIT_CPU)); |
| 2450 | | #endif |
| 2451 | | #ifdef RLIMIT_DATA |
| 2452 | | rb_define_const(rb_mProcess, "RLIMIT_DATA", INT2FIX(RLIMIT_DATA)); |
| 2453 | | #endif |
| 2454 | | #ifdef RLIMIT_FSIZE |
| 2455 | | rb_define_const(rb_mProcess, "RLIMIT_FSIZE", INT2FIX(RLIMIT_FSIZE)); |
| 2456 | | #endif |
| 2457 | | #ifdef RLIMIT_NOFILE |
| 2458 | | rb_define_const(rb_mProcess, "RLIMIT_NOFILE", INT2FIX(RLIMIT_NOFILE)); |
| 2459 | | #endif |
| 2460 | | #ifdef RLIMIT_STACK |
| 2461 | | rb_define_const(rb_mProcess, "RLIMIT_STACK", INT2FIX(RLIMIT_STACK)); |
| 2462 | | #endif |
| 2463 | | #ifdef RLIMIT_AS |
| 2464 | | rb_define_const(rb_mProcess, "RLIMIT_AS", INT2FIX(RLIMIT_AS)); |
| 2465 | | #endif |
| 2466 | | #ifdef RLIMIT_MEMLOCK |
| 2467 | | rb_define_const(rb_mProcess, "RLIMIT_MEMLOCK", INT2FIX(RLIMIT_MEMLOCK)); |
| 2468 | | #endif |
| 2469 | | #ifdef RLIMIT_NPROC |
| 2470 | | rb_define_const(rb_mProcess, "RLIMIT_NPROC", INT2FIX(RLIMIT_NPROC)); |
| 2471 | | #endif |
| 2472 | | #ifdef RLIMIT_RSS |
| 2473 | | rb_define_const(rb_mProcess, "RLIMIT_RSS", INT2FIX(RLIMIT_RSS)); |
| 2474 | | #endif |
| 2475 | | #ifdef RLIMIT_SBSIZE |
| 2476 | | rb_define_const(rb_mProcess, "RLIMIT_SBSIZE", INT2FIX(RLIMIT_SBSIZE)); |
| 2477 | | #endif |
| 2478 | | #endif |
| 2479 | | |
| 2480 | | rb_define_module_function(rb_mProcess, "uid", proc_getuid, 0); |
| 2481 | | rb_define_module_function(rb_mProcess, "uid=", proc_setuid, 1); |
| 2482 | | rb_define_module_function(rb_mProcess, "gid", proc_getgid, 0); |
| 2483 | | rb_define_module_function(rb_mProcess, "gid=", proc_setgid, 1); |
| 2484 | | rb_define_module_function(rb_mProcess, "euid", proc_geteuid, 0); |
| 2485 | | rb_define_module_function(rb_mProcess, "euid=", proc_seteuid, 1); |
| 2486 | | rb_define_module_function(rb_mProcess, "egid", proc_getegid, 0); |
| 2487 | | rb_define_module_function(rb_mProcess, "egid=", proc_setegid, 1); |
| 2488 | | rb_define_module_function(rb_mProcess, "initgroups", proc_initgroups, 2); |
| 2489 | | rb_define_module_function(rb_mProcess, "groups", proc_getgroups, 0); |
| 2490 | | rb_define_module_function(rb_mProcess, "groups=", proc_setgroups, 1); |
| 2491 | | rb_define_module_function(rb_mProcess, "maxgroups", proc_getmaxgroups, 0); |
| 2492 | | rb_define_module_function(rb_mProcess, "maxgroups=", proc_setmaxgroups, 1); |
| 2493 | | |
| 2494 | | rb_define_module_function(rb_mProcess, "times", rb_proc_times, 0); |
| 2495 | | |
| 2496 | | #if defined(HAVE_TIMES) || defined(_WIN32) |
| 2497 | | S_Tms = rb_struct_define("Tms", "utime", "stime", "cutime", "cstime", NULL); |
| 2498 | | #endif |
| 2499 | | |
| 2500 | | SAVED_USER_ID = geteuid(); |
| 2501 | | SAVED_GROUP_ID = getegid(); |
| 2502 | | |
| 2503 | | rb_mProcUID = rb_define_module_under(rb_mProcess, "UID"); |
| 2504 | | rb_mProcGID = rb_define_module_under(rb_mProcess, "GID"); |
| 2505 | | |
| 2506 | | rb_define_module_function(rb_mProcUID, "rid", proc_getuid, 0); |
| 2507 | | rb_define_module_function(rb_mProcGID, "rid", proc_getgid, 0); |
| 2508 | | rb_define_module_function(rb_mProcUID, "eid", proc_geteuid, 0); |
| 2509 | | rb_define_module_function(rb_mProcGID, "eid", proc_getegid, 0); |
| 2510 | | rb_define_module_function(rb_mProcUID, "change_privilege", p_uid_change_privilege, 1); |
| 2511 | | rb_define_module_function(rb_mProcGID, "change_privilege", p_gid_change_privilege, 1); |
| 2512 | | rb_define_module_function(rb_mProcUID, "grant_privilege", p_uid_grant_privilege, 1); |
| 2513 | | rb_define_module_function(rb_mProcGID, "grant_privilege", p_gid_grant_privilege, 1); |
| 2514 | | rb_define_alias(rb_mProcUID, "eid=", "grant_privilege"); |
| 2515 | | rb_define_alias(rb_mProcGID, "eid=", "grant_privilege"); |
| 2516 | | rb_define_module_function(rb_mProcUID, "re_exchange", p_uid_exchange, 0); |
| 2517 | | rb_define_module_function(rb_mProcGID, "re_exchange", p_gid_exchange, 0); |
| 2518 | | rb_define_module_function(rb_mProcUID, "re_exchangeable?", p_uid_exchangeable, 0); |
| 2519 | | rb_define_module_function(rb_mProcGID, "re_exchangeable?", p_gid_exchangeable, 0); |
| 2520 | | rb_define_module_function(rb_mProcUID, "sid_available?", p_uid_have_saved_id, 0); |
| 2521 | | rb_define_module_function(rb_mProcGID, "sid_available?", p_gid_have_saved_id, 0); |
| 2522 | | rb_define_module_function(rb_mProcUID, "switch", p_uid_switch, 0); |
| 2523 | | rb_define_module_function(rb_mProcGID, "switch", p_gid_switch, 0); |
| 2524 | | |
| 2525 | | rb_mProcID_Syscall = rb_define_module_under(rb_mProcess, "Sys"); |
| 2526 | | |
| 2527 | | rb_define_module_function(rb_mProcID_Syscall, "getuid", proc_getuid, 0); |
| 2528 | | rb_define_module_function(rb_mProcID_Syscall, "geteuid", proc_geteuid, 0); |
| 2529 | | rb_define_module_function(rb_mProcID_Syscall, "getgid", proc_getgid, 0); |
| 2530 | | rb_define_module_function(rb_mProcID_Syscall, "getegid", proc_getegid, 0); |
| 2531 | | |
| 2532 | | rb_define_module_function(rb_mProcID_Syscall, "setuid", p_sys_setuid, 1); |
| 2533 | | rb_define_module_function(rb_mProcID_Syscall, "setgid", p_sys_setgid, 1); |
| 2534 | | |
| 2535 | | rb_define_module_function(rb_mProcID_Syscall, "setruid", p_sys_setruid, 1); |
| 2536 | | rb_define_module_function(rb_mProcID_Syscall, "setrgid", p_sys_setrgid, 1); |
| 2537 | | |
| 2538 | | rb_define_module_function(rb_mProcID_Syscall, "seteuid", p_sys_seteuid, 1); |
| 2539 | | rb_define_module_function(rb_mProcID_Syscall, "setegid", p_sys_setegid, 1); |
| 2540 | | |
| 2541 | | rb_define_module_function(rb_mProcID_Syscall, "setreuid", p_sys_setreuid, 2); |
| 2542 | | rb_define_module_function(rb_mProcID_Syscall, "setregid", p_sys_setregid, 2); |
| 2543 | | |
| 2544 | | rb_define_module_function(rb_mProcID_Syscall, "setresuid", p_sys_setresuid, 3); |
| 2545 | | rb_define_module_function(rb_mProcID_Syscall, "setresgid", p_sys_setresgid, 3); |
| 2546 | | rb_define_module_function(rb_mProcID_Syscall, "issetugid", p_sys_issetugid, 0); |
| | 2359 | SAND_COPY_KERNEL("exec"); |
| | 2360 | SAND_COPY_KERNEL("fork"); |
| | 2361 | SAND_COPY_KERNEL("exit!"); |
| | 2362 | SAND_COPY_KERNEL("system"); |
| | 2363 | SAND_COPY_KERNEL("sleep"); |
| | 2364 | |
| | 2365 | VALUE rb_mProcess = rb_const_get_at(rb_cObject, rb_intern("Process")); |
| | 2366 | kit->mProcess = sandbox_defmodule(kit, "Process"); |
| | 2367 | SAND_COPY_CONST(mProcess, "WNOHANG"); |
| | 2368 | SAND_COPY_CONST(mProcess, "WUNTRACED"); |
| | 2369 | |
| | 2370 | SAND_COPY_S(mProcess, "fork"); |
| | 2371 | SAND_COPY_S(mProcess, "exit!"); |
| | 2372 | SAND_COPY_S(mProcess, "exit"); |
| | 2373 | SAND_COPY_S(mProcess, "abort"); |
| | 2374 | |
| | 2375 | SAND_COPY_S(mProcess, "kill"); |
| | 2376 | SAND_COPY_S(mProcess, "wait"); |
| | 2377 | SAND_COPY_S(mProcess, "wait2"); |
| | 2378 | SAND_COPY_S(mProcess, "waitpid"); |
| | 2379 | SAND_COPY_S(mProcess, "waitpid2"); |
| | 2380 | SAND_COPY_S(mProcess, "waitall"); |
| | 2381 | SAND_COPY_S(mProcess, "detach"); |
| | 2382 | |
| | 2383 | VALUE rb_cProcStatus = rb_const_get_at(rb_mProcess, rb_intern("Status")); |
| | 2384 | kit->cProcStatus = sandbox_defclass_under(kit, kit->mProcess, "Status", kit->cObject); |
| | 2385 | SAND_UNDEF(cProcStatus, "new"); |
| | 2386 | |
| | 2387 | SAND_COPY(cProcStatus, "=="); |
| | 2388 | SAND_COPY(cProcStatus, "&"); |
| | 2389 | SAND_COPY(cProcStatus, ">>"); |
| | 2390 | SAND_COPY(cProcStatus, "to_i"); |
| | 2391 | SAND_COPY(cProcStatus, "to_int"); |
| | 2392 | SAND_COPY(cProcStatus, "to_s"); |
| | 2393 | SAND_COPY(cProcStatus, "inspect"); |
| | 2394 | |
| | 2395 | SAND_COPY(cProcStatus, "pid"); |
| | 2396 | |
| | 2397 | SAND_COPY(cProcStatus, "stopped?"); |
| | 2398 | SAND_COPY(cProcStatus, "stopsig"); |
| | 2399 | SAND_COPY(cProcStatus, "signaled?"); |
| | 2400 | SAND_COPY(cProcStatus, "termsig"); |
| | 2401 | SAND_COPY(cProcStatus, "exited?"); |
| | 2402 | SAND_COPY(cProcStatus, "exitstatus"); |
| | 2403 | SAND_COPY(cProcStatus, "success?"); |
| | 2404 | SAND_COPY(cProcStatus, "coredump?"); |
| | 2405 | |
| | 2406 | SAND_COPY_S(mProcess, "pid"); |
| | 2407 | SAND_COPY_S(mProcess, "ppid"); |
| | 2408 | |
| | 2409 | SAND_COPY_S(mProcess, "getpgrp"); |
| | 2410 | SAND_COPY_S(mProcess, "setpgrp"); |
| | 2411 | SAND_COPY_S(mProcess, "getpgid"); |
| | 2412 | SAND_COPY_S(mProcess, "setpgid"); |
| | 2413 | |
| | 2414 | SAND_COPY_S(mProcess, "setsid"); |
| | 2415 | |
| | 2416 | SAND_COPY_S(mProcess, "getpriority"); |
| | 2417 | SAND_COPY_S(mProcess, "setpriority"); |
| | 2418 | |
| | 2419 | SAND_COPY_IF_CONST(mProcess, "PRIO_PROCESS"); |
| | 2420 | SAND_COPY_IF_CONST(mProcess, "PRIO_PGRP"); |
| | 2421 | SAND_COPY_IF_CONST(mProcess, "PRIO_USER"); |
| | 2422 | |
| | 2423 | SAND_COPY_S(mProcess, "getrlimit"); |
| | 2424 | SAND_COPY_S(mProcess, "setrlimit"); |
| | 2425 | |
| | 2426 | SAND_COPY_IF_CONST(mProcess, "RLIM_INFINITY"); |
| | 2427 | SAND_COPY_IF_CONST(mProcess, "RLIM_SAVED_MAX"); |
| | 2428 | SAND_COPY_IF_CONST(mProcess, "RLIM_SAVED_CUR"); |
| | 2429 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_CORE"); |
| | 2430 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_CPU"); |
| | 2431 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_DATA"); |
| | 2432 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_FSIZE"); |
| | 2433 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_NOFILE"); |
| | 2434 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_STACK"); |
| | 2435 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_AS"); |
| | 2436 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_MEMLOCK"); |
| | 2437 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_NPROC"); |
| | 2438 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_RSS"); |
| | 2439 | SAND_COPY_IF_CONST(mProcess, "RLIMIT_SBSIZE"); |
| | 2440 | |
| | 2441 | SAND_COPY_S(mProcess, "uid"); |
| | 2442 | SAND_COPY_S(mProcess, "uid="); |
| | 2443 | SAND_COPY_S(mProcess, "gid"); |
| | 2444 | SAND_COPY_S(mProcess, "gid="); |
| | 2445 | SAND_COPY_S(mProcess, "euid"); |
| | 2446 | SAND_COPY_S(mProcess, "euid="); |
| | 2447 | SAND_COPY_S(mProcess, "egid"); |
| | 2448 | SAND_COPY_S(mProcess, "egid="); |
| | 2449 | SAND_COPY_S(mProcess, "initgroups"); |
| | 2450 | SAND_COPY_S(mProcess, "groups"); |
| | 2451 | SAND_COPY_S(mProcess, "groups="); |
| | 2452 | SAND_COPY_S(mProcess, "maxgroups"); |
| | 2453 | SAND_COPY_S(mProcess, "maxgroups="); |
| | 2454 | |
| | 2455 | SAND_COPY_S(mProcess, "times"); |
| | 2456 | |
| | 2457 | /* |
| | 2458 | SAVED_USER_ID = geteuid(); |
| | 2459 | SAVED_GROUP_ID = getegid(); |