-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.c
More file actions
129 lines (113 loc) · 2.71 KB
/
misc.c
File metadata and controls
129 lines (113 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* This file is part of uxlaunch
*
* (C) Copyright 2009 Intel Corporation
* Authors:
* Auke Kok <auke@linux.intel.com>
* Arjan van de Ven <arjan@linux.intel.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "uxlaunch.h"
static int ssh_agent_pid;
/*
* ssh-agent prints a bunch of env variables to its stdout that we need to put in
* the environment.
*/
void start_ssh_agent(void)
{
FILE *file;
char line[4096];
memset(line, 0, 4096);
file = popen("/usr/bin/ssh-agent", "r");
if (!file) {
lprintf("Failed to start ssh-agent");
return;
}
/*
* ssh-agent output looks like this:
*
* SSH_AUTH_SOCK=/tmp/ssh-ccZMs16230/agent.16230; export SSH_AUTH_SOCK;
* SSH_AGENT_PID=16231; export SSH_AGENT_PID;
* echo Agent pid 16231;
*
* so search for "; export", cut that off. Then split at the = for env var name
* and value.
*/
while (!feof(file)) {
char *c;
if (fgets(line, 4095, file)==NULL)
break;
c = strstr(line, "; export");
if (c) {
char *c2;
*c = 0;
c2 = strchr(line, '=');
if (c2) {
*c2 = 0;
c2++;
setenv(line, c2, 1);
/* store PID for later */
if (!strcmp(line, "SSH_AGENT_PID"))
ssh_agent_pid = atoi(c2);
}
}
}
pclose(file);
log_environment();
}
void stop_ssh_agent(void)
{
kill(ssh_agent_pid, SIGTERM);
}
/*
* helper function to make debug easier
*/
void start_bash(void)
{
int ret;
fprintf(stderr, "Starting bash shell -- type exit to continue\n");
ret = system("/bin/bash");
if (ret != EXIT_SUCCESS)
lprintf("bash returned an error");
}
/*
* We want to start gconf early, by hand, so that it can start processing the
* XML well before someone needs it to cut down the total time
*/
void start_gconf(void)
{
int ret;
ret = system("gconftool-2 --spawn");
if (ret)
lprintf("failure to start gconftool-2: %d", ret);
}
/*
* Start the background screensaver daemon.
* Also, if /etc/sysconfig/lock-screen exists,
* start with the screen locked.
*
* We do this instead of using a login screen, for the
* cases that people want a password on their device.
*/
void maybe_start_screensaver(void)
{
int ret;
/* the screensaver becomes a daemon */
ret = system("/usr/bin/gnome-screensaver");
if (!ret)
lprintf("Failed to launch /usr/bin/gnome-screensaver");
if (!access("/etc/sysconfig/lock-screen", R_OK)) {
ret = system("/usr/bin/gnome-screensaver-command --lock");
if (!ret)
lprintf("Failed to launch /usr/bin/gnome-screensaver-command");
}
}