~jamesodhunt/upstart/async-spawn.WIP

« back to all changes in this revision

Viewing changes to init/control.c

  • Committer: James Hunt
  • Date: 2014-05-08 08:51:27 UTC
  • mfrom: (1588.1.32 upstart)
  • Revision ID: james.hunt@ubuntu.com-20140508085127-7rd5vrwkdaqpfypu
* Sync with lp:upstart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1288
1288
 
1289
1289
        nih_assert (message);
1290
1290
        nih_assert (job_details);
1291
 
        nih_assert (var);
 
1291
 
 
1292
        if (! control_check_permission (message)) {
 
1293
                nih_dbus_error_raise_printf (
 
1294
                        DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
 
1295
                        _("You do not have permission to modify job environment"));
 
1296
                return -1;
 
1297
        }
1292
1298
 
1293
1299
        if (job_details[0]) {
1294
1300
                job_name = job_details[0];
1302
1308
                return -1;
1303
1309
        }
1304
1310
 
1305
 
        if (! control_check_permission (message)) {
1306
 
                nih_dbus_error_raise_printf (
1307
 
                        DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1308
 
                        _("You do not have permission to modify job environment"));
 
1311
        if (! var || ! *var) {
 
1312
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
 
1313
                                _("Variable may not be empty string"));
1309
1314
                return -1;
1310
1315
        }
1311
1316
 
1386
1391
 
1387
1392
        nih_assert (message);
1388
1393
        nih_assert (job_details);
1389
 
        nih_assert (name);
1390
1394
 
1391
1395
        if (! control_check_permission (message)) {
1392
1396
                nih_dbus_error_raise_printf (
1395
1399
                return -1;
1396
1400
        }
1397
1401
 
 
1402
        if (! name || ! *name) {
 
1403
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
 
1404
                                _("Variable may not be empty string"));
 
1405
                return -1;
 
1406
        }
 
1407
 
1398
1408
        if (job_details[0]) {
1399
1409
                job_name = job_details[0];
1400
1410
 
1490
1500
                return -1;
1491
1501
        }
1492
1502
 
 
1503
        if (! name || ! *name) {
 
1504
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
 
1505
                                _("Variable may not be empty string"));
 
1506
                return -1;
 
1507
        }
 
1508
 
1493
1509
        if (job_details[0]) {
1494
1510
                job_name = job_details[0];
1495
1511
 
1649
1665
        nih_assert (message);
1650
1666
        nih_assert (job_details);
1651
1667
 
 
1668
        if (! control_check_permission (message)) {
 
1669
                nih_dbus_error_raise_printf (
 
1670
                        DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
 
1671
                        _("You do not have permission to modify job environment"));
 
1672
                return -1;
 
1673
        }
 
1674
 
1652
1675
        if (job_details[0]) {
1653
1676
                job_name = job_details[0];
1654
1677
 
1661
1684
                return -1;
1662
1685
        }
1663
1686
 
1664
 
        if (! control_check_permission (message)) {
1665
 
                nih_dbus_error_raise_printf (
1666
 
                        DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1667
 
                        _("You do not have permission to modify job environment"));
1668
 
                return -1;
1669
 
        }
1670
 
 
1671
1687
        /* Verify that job name is valid */
1672
1688
        if (job_name && ! strlen (job_name)) {
1673
1689
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1887
1903
 
1888
1904
        return 0;
1889
1905
}
 
1906
 
 
1907
/**
 
1908
 * control_serialise_bus_address:
 
1909
 *
 
1910
 * Convert control_bus_address into JSON representation.
 
1911
 *
 
1912
 * Returns: JSON string representing control_bus_address or NULL if
 
1913
 * control_bus_address not set or on error.
 
1914
 *
 
1915
 * Note: If NULL is returned, check the value of control_bus_address
 
1916
 * itself to determine if the error is real.
 
1917
 **/
 
1918
json_object *
 
1919
control_serialise_bus_address (void)
 
1920
{
 
1921
        control_init ();
 
1922
 
 
1923
        /* A NULL return represents a JSON null */
 
1924
        return control_bus_address
 
1925
                ? json_object_new_string (control_bus_address)
 
1926
                : NULL;
 
1927
}
 
1928
 
 
1929
/**
 
1930
 * control_deserialise_bus_address:
 
1931
 *
 
1932
 * @json: root of JSON-serialised state.
 
1933
 *
 
1934
 * Convert JSON representation of control_bus_address back into a native
 
1935
 * string.
 
1936
 *
 
1937
 * Returns: 0 on success, -1 on error.
 
1938
 **/
 
1939
int
 
1940
control_deserialise_bus_address (json_object *json)
 
1941
{
 
1942
        const char  *address;
 
1943
 
 
1944
        nih_assert (json);
 
1945
        nih_assert (! control_bus_address);
 
1946
 
 
1947
        control_init ();
 
1948
 
 
1949
        /* control_bus_address was never set */
 
1950
        if (state_check_json_type (json, null))
 
1951
                return 0;
 
1952
 
 
1953
        if (! state_check_json_type (json, string))
 
1954
                goto error;
 
1955
 
 
1956
        address = json_object_get_string (json);
 
1957
        if (! address)
 
1958
                goto error;
 
1959
 
 
1960
        control_bus_address = nih_strdup (NULL, address);
 
1961
        if (! control_bus_address)
 
1962
                goto error;
 
1963
 
 
1964
        return 0;
 
1965
 
 
1966
error:
 
1967
        return -1;
 
1968
}