982
* control_notify_cgroup_manager_address:
984
* @message: D-Bus connection and message received,
985
* @address: D-Bus address that cgroup manager is connected to.
987
* Implements the NotifyCGroupManagerAddress method of the
988
* com.ubuntu.Upstart interface.
990
* Called to allow the cgroup manager to be contacted,
991
* thus enabling the cgroup stanza.
993
* Returns: zero on success, negative value on raised error.
996
control_notify_cgroup_manager_address (void *data,
997
NihDBusMessage *message,
1000
nih_assert (message);
1001
nih_assert (address);
1003
if (! control_check_permission (message)) {
1004
nih_dbus_error_raise_printf (
1005
DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1006
_("You do not have permission to notify cgroup manager address"));
1010
#ifdef ENABLE_CGROUPS
1011
if (! cgroup_support_enabled ())
1014
/* Already called */
1015
if (cgroup_manager_available ())
1018
if (! cgroup_manager_set_address (address)) {
1019
nih_dbus_error_raise_printf (DBUS_ERROR_NO_MEMORY,
1020
_("Out of Memory"));
1024
nih_debug ("set cgroup manager address");
1026
if (! job_class_induct_jobs ()) {
1027
nih_dbus_error_raise_printf (DBUS_ERROR_NO_MEMORY,
1028
_("Out of Memory"));
1033
nih_debug ("cgroup support not available");
1034
#endif /* ENABLE_CGROUPS */
978
1040
* control_bus_flush:
980
1042
* Drain any remaining messages in the D-Bus queue.
1318
* control_set_env_list:
1321
* @message: D-Bus connection and message received,
1322
* @job_details: name and instance of job to apply operation to,
1323
* @vars: array of name[/value] pairs of environment variables to set,
1324
* @replace: TRUE if @name should be overwritten if already set, else
1327
* Implements the SetEnvList method of the com.ubuntu.Upstart
1330
* Called to request Upstart store one or more name/value pairs.
1332
* If @job_details is empty, change will be applied to all job
1333
* environments, else only apply changes to specific job environment
1334
* encoded within @job_details.
1336
* Returns: zero on success, negative value on raised error.
1339
control_set_env_list (void *data,
1340
NihDBusMessage *message,
1341
char * const *job_details,
1347
char *job_name = NULL;
1348
char *instance = NULL;
1351
nih_assert (message);
1352
nih_assert (job_details);
1355
if (! control_check_permission (message)) {
1356
nih_dbus_error_raise_printf (
1357
DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1358
_("You do not have permission to modify job environment"));
1362
if (job_details[0]) {
1363
job_name = job_details[0];
1365
/* this can be a null value */
1366
instance = job_details[1];
1367
} else if (getpid () == 1) {
1368
nih_dbus_error_raise_printf (
1369
DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1370
_("Not permissible to modify PID 1 job environment"));
1374
/* Verify that job name is valid */
1375
if (job_name && ! strlen (job_name)) {
1376
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1377
_("Job may not be empty string"));
1381
/* Get the relevant session */
1382
session = session_from_dbus (NULL, message);
1384
/* Chroot sessions must not be able to influence
1385
* the outside system.
1387
if (session && session->chroot) {
1388
nih_warn (_("Ignoring set env request from chroot session"));
1392
/* Lookup the job */
1393
control_get_job (session, job, job_name, instance);
1395
for (var = vars; var && *var; var++) {
1396
nih_local char *envvar = NULL;
1399
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1400
_("Variable may not be empty string"));
1404
/* If variable does not contain a delimiter, add one to ensure
1405
* it gets entered into the job environment table. Without the
1406
* delimiter, the variable will be silently ignored unless it's
1407
* already set in inits environment. But in that case there is
1408
* no point in setting such a variable to its already existing
1411
if (! strchr (*var, '=')) {
1412
envvar = NIH_MUST (nih_sprintf (NULL, "%s=", *var));
1414
envvar = NIH_MUST (nih_strdup (NULL, *var));
1418
/* Modify job-specific environment */
1419
nih_assert (job->env);
1421
NIH_MUST (environ_add (&job->env, job, NULL, replace, envvar));
1422
} else if (job_class_environment_set (envvar, replace) < 0) {
1423
nih_return_no_memory_error (-1);
1256
1431
* control_set_env:
1258
1433
* @data: not used,
1280
1455
const char *var,
1458
nih_local char **vars = NULL;
1461
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1462
_("Variable may not be empty string"));
1466
vars = NIH_MUST (nih_str_array_new (NULL));
1468
NIH_MUST (nih_str_array_add (&vars, NULL, NULL, var));
1470
return control_set_env_list (data, message, job_details, vars, replace);
1474
* control_unset_env_list:
1477
* @message: D-Bus connection and message received,
1478
* @job_details: name and instance of job to apply operation to,
1479
* @names: array of variables to clear from the job environment array.
1481
* Implements the UnsetEnvList method of the com.ubuntu.Upstart
1484
* Called to request Upstart remove one or more variables from the job
1485
* environment array.
1487
* Returns: zero on success, negative value on raised error.
1490
control_unset_env_list (void *data,
1491
NihDBusMessage *message,
1492
char * const *job_details,
1493
char * const *names)
1283
1495
Session *session;
1284
1496
Job *job = NULL;
1285
1497
char *job_name = NULL;
1286
1498
char *instance = NULL;
1287
nih_local char *envvar = NULL;
1289
1501
nih_assert (message);
1290
1502
nih_assert (job_details);
1292
1505
if (! control_check_permission (message)) {
1293
1506
nih_dbus_error_raise_printf (
1328
1535
* the outside system.
1330
1537
if (session && session->chroot) {
1331
nih_warn (_("Ignoring set env request from chroot session"));
1538
nih_warn (_("Ignoring unset env request from chroot session"));
1335
1542
/* Lookup the job */
1336
1543
control_get_job (session, job, job_name, instance);
1338
/* If variable does not contain a delimiter, add one to ensure
1339
* it gets entered into the job environment table. Without the
1340
* delimiter, the variable will be silently ignored unless it's
1341
* already set in inits environment. But in that case there is
1342
* no point in setting such a variable to its already existing
1345
if (! strchr (var, '='))
1346
envvar = NIH_MUST (nih_sprintf (NULL, "%s=", var));
1348
envvar = NIH_MUST (nih_strdup (NULL, var));
1351
/* Modify job-specific environment */
1353
nih_assert (job->env);
1355
NIH_MUST (environ_add (&job->env, job, NULL, replace, envvar));
1545
for (name = names; name && *name; name++) {
1547
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1548
_("Variable may not be empty string"));
1553
/* Modify job-specific environment */
1554
nih_assert (job->env);
1556
if (! environ_remove (&job->env, job, NULL, *name))
1558
} else if (job_class_environment_unset (*name) < 0) {
1359
if (job_class_environment_set (envvar, replace) < 0)
1360
nih_return_no_memory_error (-1);
1566
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1568
_("No such variable"), *name);
1384
1591
char * const *job_details,
1385
1592
const char *name)
1389
char *job_name = NULL;
1390
char *instance = NULL;
1392
nih_assert (message);
1393
nih_assert (job_details);
1395
if (! control_check_permission (message)) {
1396
nih_dbus_error_raise_printf (
1397
DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1398
_("You do not have permission to modify job environment"));
1402
if (! name || ! *name) {
1403
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1404
_("Variable may not be empty string"));
1408
if (job_details[0]) {
1409
job_name = job_details[0];
1411
/* this can be a null value */
1412
instance = job_details[1];
1413
} else if (getpid () == 1) {
1414
nih_dbus_error_raise_printf (
1415
DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1416
_("Not permissible to modify PID 1 job environment"));
1420
/* Verify that job name is valid */
1421
if (job_name && ! strlen (job_name)) {
1422
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1423
_("Job may not be empty string"));
1427
/* Get the relevant session */
1428
session = session_from_dbus (NULL, message);
1430
/* Chroot sessions must not be able to influence
1431
* the outside system.
1433
if (session && session->chroot) {
1434
nih_warn (_("Ignoring unset env request from chroot session"));
1438
/* Lookup the job */
1439
control_get_job (session, job, job_name, instance);
1442
/* Modify job-specific environment */
1444
nih_assert (job->env);
1446
if (! environ_remove (&job->env, job, NULL, name))
1452
if (job_class_environment_unset (name) < 0)
1458
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1460
_("No such variable"), name);
1594
nih_local char **names = NULL;
1597
nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1598
_("Variable may not be empty string"));
1602
names = NIH_MUST (nih_str_array_new (NULL));
1604
NIH_MUST (nih_str_array_add (&names, NULL, NULL, name));
1606
return control_unset_env_list (data, message, job_details, names);