~xnox/upstart/empty-session

« back to all changes in this revision

Viewing changes to init/control.c

  • Committer: Dimitri John Ledkov
  • Date: 2014-03-06 15:21:54 UTC
  • mfrom: (1579.1.1 upstart-bug-1258098)
  • Revision ID: dimitri.ledkov@canonical.com-20140306152154-xq00rhetbcenvvzq
mergeĀ lp:~jamesodhunt/upstart/bug-1258098

Show diffs side-by-side

added added

removed removed

Lines of Context:
1903
1903
 
1904
1904
        return 0;
1905
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
}