Skip to content

Commit 7f71d00

Browse files
Add more launcher logging
1 parent 076e22b commit 7f71d00

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

launcher/main.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ LIPCcode pause_callback(LIPC* lipc, const char* property, void* value, void* dat
5959
}
6060

6161
LIPCcode unload_callback(LIPC* lipc, const char* property, void* value, void* data) {
62-
Log("Unloading shell integration launcher");
62+
Log("unload_callback");
6363

6464
// Kill the app if it's running
6565
if (app_pid > 0) {
@@ -77,15 +77,18 @@ LIPCcode unload_callback(LIPC* lipc, const char* property, void* value, void* da
7777

7878
char* getScriptCommand(char* scriptPath)
7979
{
80+
Log("Loading script file");
8081
FILE* file = fopen(scriptPath, "r");
8182
if (!file) {
8283
return NULL;
8384
}
8485

86+
Log("Reading header");
8587
struct ScriptHeader header;
8688
readScriptHeader(file, &header);
8789
fclose(file);
8890

91+
Log("Escaping path");
8992
char* escapedPath = (char*) malloc((strlen(scriptPath) * 2) + 1);
9093
int escapedPathLength = 0;
9194
for (size_t i=0; i < strlen(scriptPath); i++) {
@@ -96,25 +99,30 @@ char* getScriptCommand(char* scriptPath)
9699
}
97100
escapedPath[escapedPathLength] = '\0';
98101

102+
Log("Building command");
99103
char* command = buildCommand("sh -l \"%s\"", escapedPath);
100104

101105
if (header.useHooks) { // useHooks script - source it and use `on_run`
106+
Log("Script uses hooks!");
102107
free(command);
103108
command = buildCommand("sh -l -c \"source \\\"%s\\\"; on_run;\"", escapedPath);
104109
}
105110
if (header.useFBInk) {
111+
Log("Script uses FBInk!");
106112
char* old_command = strdup(command);
107113
free(command);
108114
command = buildCommand("/mnt/us/libkh/bin/fbink -k; %s 2>&1 | /mnt/us/libkh/bin/fbink -y 5 -r", old_command);
109115
free(old_command);
110116
}
111117

118+
Log("Finished generating command.");
112119
freeScriptHeader(&header);
113120
free(escapedPath);
114121
return command;
115122
}
116123

117124
LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data) {
125+
Log("go_callback");
118126
char* rawFilePath = strchr((const char*)value, ':') + 6 + strlen(SERVICE_NAME) + 1;
119127
char* query = strchr(rawFilePath, '?');
120128
if (query != NULL) {
@@ -129,11 +137,11 @@ LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data)
129137
char* command = getScriptCommand(filePath);
130138
if (command == NULL)
131139
{
140+
Log("Could not get script command!");
132141
free(filePath);
133142
return stub(lipc, property, value, data);
134143
}
135144

136-
Log("Invoking app using \"%s\"", command);
137145
struct timespec time[2] = {{
138146
.tv_nsec = UTIME_NOW,
139147
.tv_sec = UTIME_NOW
@@ -146,6 +154,7 @@ LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data)
146154
LipcSetIntProperty(lipc, "com.lab126.scanner", "doFullScan", 1);
147155

148156
utimensat(0, filePath, time, 0);
157+
Log("Invoking app using \"%s\"", command);
149158
// Run the app on a background thread
150159
app_pid = fork();
151160
Log("Our app PID \"%d\"", app_pid);
@@ -162,26 +171,31 @@ LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data)
162171
#ifndef LAUNCHER_TESTING
163172
int main(void) {
164173
openlog(SERVICE_NAME, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_USER);
174+
Log("SH_INTEGRATION LAUNCHER START!");
165175
LIPCcode code;
166176
LIPC* lipc = LipcOpenEx(SERVICE_NAME, &code);
167177
if (code != LIPC_OK)
168178
return 1;
169-
179+
180+
Log("Registering properties");
170181
LipcRegisterStringProperty(lipc, "load", NULL, stub, NULL);
171182
LipcRegisterStringProperty(lipc, "unload", NULL, unload_callback, NULL);
172183
LipcRegisterStringProperty(lipc, "pause", NULL, pause_callback, NULL);
173184
LipcRegisterStringProperty(lipc, "go", NULL, go_callback, NULL);
174185
LipcSetStringProperty(lipc, "com.lab126.appmgrd", "runresult", "0:" SERVICE_NAME);
175186

187+
Log("Waiting to exit...");
176188
while (!shouldExit) {
177189
sleep(1);
178190

179191
if (app_pid > 0) { // This is the parent process AND we have spwned the child
192+
Log("Child spawned, waiting to quit");
180193
// Wait for child process to quit
181194
waitpid(app_pid, NULL, 0);
182195

183196
app_pid = -1; // So we know the program has quit
184197

198+
Log("Exiting");
185199
// Calls unload - gracefully exits
186200
char* value;
187201
LipcGetStringProperty(lipc, "com.lab126.appmgrd", "popAppHistory", &value);

0 commit comments

Comments
 (0)