Skip to content

Commit

Permalink
(a12/lua/shmif) afsrv_net handover exec env. wrong
Browse files Browse the repository at this point in the history
Surprisingly enough most of afsrv-net loading appl actually worked with
a completely broken env. The handover exec required the key=val format
for envv and not the {key,val,..} form.

Also switch the join command to use absolute path for the connection
socket to avoid collisions between an outer arcan and the chained one
vis a vis XDG_RUNTIME_PATH.
  • Loading branch information
letoram committed Nov 2, 2023
1 parent 794dffb commit 9371c2e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/a12/net/dir_cl.c
Expand Up @@ -327,12 +327,14 @@ static pid_t exec_cpath(struct a12_state* S,
fchdir(dir->clopt->basedir);

setsid();
setenv("XDG_RUNTIME_DIR", "./", 1);
setenv("XDG_RUNTIME_DIR", ".", 1);
dup2(pstdin[0], STDIN_FILENO);
close(pstdin[0]);
close(pstdin[1]);
close(pstdout[0]);

/*
* keeping these open makes it easier to see when something goes wrong with _lwa
* close(STDERR_FILENO);
close(STDOUT_FILENO);
open("/dev/null", O_WRONLY);
Expand Down Expand Up @@ -448,7 +450,7 @@ static void process_thread(struct ioloop_shared* I, bool ok)
int dfd;
char* key = arcan_shmif_connect(cbuf, NULL, &dfd);
a12int_trace(A12_TRACE_DIRECTORY,
"appl_monitor:connect=%s:ok=%s", &buf[5], key ? "true":"false");
"appl_monitor:connect=%s:ok=%s", cbuf, key ? "true":"false");
if (!key){
return;
}
Expand Down Expand Up @@ -479,7 +481,6 @@ static void process_thread(struct ioloop_shared* I, bool ok)
snprintf(
(char*)ev.ext.message.data, lim, "%d", I->cbt->clopt->applid);
a12_channel_enqueue(I->S, &ev);
arcan_shmif_resize(&I->shmif, 64, 64);
runner_shmif(I);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/a12/net/dir_srv_worker.c
Expand Up @@ -396,6 +396,7 @@ static void do_external_event(
}
break;
default:
break;
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/engine/arcan_lua.c
Expand Up @@ -11704,8 +11704,20 @@ static int net_open(lua_State* ctx)
return 1;
}

/* we need to resolve the full path from within the context here, as the XDG_
* runtime and similar paths may differ from outer to inner due to LWA having
* one set of needs, while the cleanup from afsrv_net/arcan-net need another. */
char path[PATH_MAX];
if (0 > arcan_shmif_resolve_connpath(co, path, PATH_MAX)){
arcan_warning("couldn't resolve socket path");
arcan_frameserver_free(newref);
lua_pushvid(ctx, ARCAN_EID);
free(host);
return 1;
}

arcan_conductor_register_frameserver(newref);
arcan_monitor_fsrvvid(co);
arcan_monitor_fsrvvid(path);
trace_allocation(ctx, "net_listen", newref->vid);

/* only different thing to regular frameserver setup is that the monitor need to
Expand Down
25 changes: 14 additions & 11 deletions src/frameserver/net/default/net.c
Expand Up @@ -506,22 +506,25 @@ static pid_t dircl_exec(struct a12_state* S,
buf, NULL /* applname */
};

char* envv[] = {
"PATH", getenv("PATH"),
"HOME", getenv("HOME"),
"TERM", getenv("TERM"),
"SHELL", getenv("SHELL"),
"ARCAN_LOGPATH", getenv("ARCAN_LOGPATH"),
"ARCAN_RESOURCEPATH", getenv("ARCAN_RESOURCEPATH"),
"ARCAN_STATEPATH", getenv("ARCAN_STATEPATH"),
"XDG_RUNTIME_DIR", getenv("XDG_RUNTIME_DIR"),
NULL,
};
const char* keys[] = {"TERM", "SHELL", "ARCAN_LOGPATH", "HOME",
"ARCAN_RESOURCEPATH", "ARCAN_STATEPATH", "XDG_RUNTIME_DIR", "PATH", NULL};
char* envv[COUNT_OF(keys)] = {0};

size_t j = 0;
for (size_t i = 0; keys[i]; i++){
if (!getenv(keys[i]))
continue;
if (-1 != asprintf(&envv[j], "%s=%s", keys[i], getenv(keys[i])))
j++;
}

int* fds[4] = {inf, outf, NULL, &pstdout[1]};
pid_t res =
arcan_shmif_handover_exec_pipe(C, client->segev, lwabin, argv, envv, 0, fds, 4);

for (size_t i = 0; envv[i]; i++)
free(envv[i]);

free(lwabin);
close(pstdout[1]);

Expand Down
2 changes: 1 addition & 1 deletion src/shmif/arcan_shmif_control.c
Expand Up @@ -1455,7 +1455,7 @@ char* arcan_shmif_connect(
size_t ofs = 0;
do {
if (-1 == read(sock, wbuf + ofs, 1)){
debug_print(FATAL, NULL, "invalid response on negotiation");
debug_print(FATAL, NULL, "invalid response on negotiation: %s", strerror(errno));
close(sock);
goto end;
}
Expand Down

0 comments on commit 9371c2e

Please sign in to comment.