~ubuntu-branches/ubuntu/trusty/systemd/trusty

« back to all changes in this revision

Viewing changes to src/core/unit-printf.c

Tags: upstream-202
ImportĀ upstreamĀ versionĀ 202

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
        ExecContext *c;
125
125
        int r;
126
126
        const char *username;
127
 
        char _cleanup_free_ *tmp = NULL;
 
127
        _cleanup_free_ char *tmp = NULL;
128
128
        uid_t uid;
129
129
        char *printed = NULL;
130
130
 
190
190
        ExecContext *c;
191
191
        int r;
192
192
        const char *username, *shell;
 
193
        char *ret;
193
194
 
194
195
        assert(u);
195
196
 
196
197
        c = unit_get_exec_context(u);
197
198
 
198
 
        /* return HOME if set, otherwise from passwd */
199
 
        if (!c || !c->user) {
200
 
                char *sh;
201
 
 
202
 
                r = get_shell(&sh);
203
 
                if (r < 0)
204
 
                        return strdup("/bin/sh");
205
 
 
206
 
                return sh;
207
 
        }
208
 
 
209
 
        username = c->user;
 
199
        if (c && c->user)
 
200
                username = c->user;
 
201
        else
 
202
                username = "root";
 
203
 
 
204
        /* return /bin/sh for root, otherwise the value from passwd */
210
205
        r = get_user_creds(&username, NULL, NULL, NULL, &shell);
211
 
        if (r < 0)
212
 
                return strdup("/bin/sh");
213
 
 
214
 
        return strdup(shell);
 
206
        if (r < 0) {
 
207
                log_warning_unit(u->id,
 
208
                                 "Failed to determine shell: %s",
 
209
                                 strerror(-r));
 
210
                return NULL;
 
211
        }
 
212
 
 
213
        if (!path_is_absolute(shell)) {
 
214
                log_warning_unit(u->id,
 
215
                                 "Shell %s is not absolute, ignoring.",
 
216
                                 shell);
 
217
        }
 
218
 
 
219
        ret = strdup(shell);
 
220
        if (!ret)
 
221
                log_oom();
 
222
 
 
223
        return ret;
215
224
}
216
225
 
217
226
char *unit_name_printf(Unit *u, const char* format) {