269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
...
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
...
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
/* messy part */
const char* tmp; //tmpdir defined?
if (!(tmp = getenv("XDG_RUNTIME_DIR")))
if (!(tmp = getenv("TMPDIR"))) tmp = "/tmp";
size_t tmpsz = strlen(tmp);
char sockn[tmpsz + 1 + sizeof "ssh."
+ 11];
strcpy(sockn, tmp);
sockn[tmpsz] = '/';
strcpy(sockn+tmpsz+1,"ssh.");
// first, gen a random identifier so we have the ability
// to know where the socket winds up
uint8_t* rndid = sockn+tmpsz+1+4;
................................................................................
s -> op = mode_kill;
kill(s -> pid, SIGUSR1);
return ok;
}
enum res activate_window(Window w) {
Display* dpy = XOpenDisplay(NULL);
XEvent ev;
long mask = SubstructureRedirectMask | SubstructureNotifyMask;
ev.xclient.type = ClientMessage;
ev.xclient.serial = 0;
ev.xclient.send_event = True;
ev.xclient.message_type = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
ev.xclient.display = dpy;
ev.xclient.window = w;
ev.xclient.format = 32;
ev.xclient.data.l[0] = 2;
ev.xclient.data.l[1] = CurrentTime;
ev.xclient.data.l[2] = 0;
if(!XSendEvent(dpy, DefaultRootWindow(dpy), False, mask, &ev)) return fail_x11;
XSync(dpy,false);
return ok;
}
................................................................................
if (init_named != NULL) {
args[argsz - 3] = "-n"; // im sorry
args[argsz - 2] = init_named;
}
execvp("urxvtc", (char* const*)args);
} else {
struct signal*s = shmlinux(
mmap(0, sizeof(struct signal), PROT_READ | PROT_WRITE, MAP_SHARED, shm, 0)
) shmsysv (
shmat(shm, 0, 0)
);
struct shmid_ds stat;
shmctl(shm, IPC_STAT, &stat);
if (stat.shm_nattch == 0) {
/* if the shm segment is not attached to any
* process, it's a relic that needs to be
* cleaned up before we do anything else. on
* a sane OS, there would be built-in non-
* persistence mechanisms for shared mem, but
* alas, as you already know, POSIX */
shmctl(shm, IPC_RMID, &stat);
goto tryagain;
}
if (s == shmlinux(MAP_FAILED) shmsysv((void*)-1))
return bad(fail_mem);
return bad(activate_window(s->wid));
}
} else if (op == mode_register)
return bad(register_window(shmlinux(shid,) init_weak,init_named));
|
|
<
<
>
|
|
|
|
|
|
|
|
|
|
>
<
<
<
<
<
<
>
>
>
>
>
>
|
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
...
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
...
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
/* messy part */
const char* tmp; //tmpdir defined?
if (!(tmp = getenv("XDG_RUNTIME_DIR")))
if (!(tmp = getenv("TMPDIR"))) tmp = "/tmp";
size_t tmpsz = strlen(tmp);
char* sockn = malloc(tmpsz + 1 + sizeof "ssh." + 11);
strcpy(sockn, tmp);
sockn[tmpsz] = '/';
strcpy(sockn+tmpsz+1,"ssh.");
// first, gen a random identifier so we have the ability
// to know where the socket winds up
uint8_t* rndid = sockn+tmpsz+1+4;
................................................................................
s -> op = mode_kill;
kill(s -> pid, SIGUSR1);
return ok;
}
enum res activate_window(Window w) {
Display* dpy = XOpenDisplay(NULL);
long mask = SubstructureRedirectMask | SubstructureNotifyMask;
XEvent ev = {
.xclient.type = ClientMessage,
.xclient.serial = 0,
.xclient.send_event = True,
.xclient.message_type = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False),
.xclient.display = dpy,
.xclient.window = w,
.xclient.format = 32,
.xclient.data.l[0] = 2,
.xclient.data.l[1] = CurrentTime,
.xclient.data.l[2] = 0,
};
if(!XSendEvent(dpy, DefaultRootWindow(dpy), False, mask, &ev)) return fail_x11;
XSync(dpy,false);
return ok;
}
................................................................................
if (init_named != NULL) {
args[argsz - 3] = "-n"; // im sorry
args[argsz - 2] = init_named;
}
execvp("urxvtc", (char* const*)args);
} else {
struct shmid_ds stat;
shmctl(shm, IPC_STAT, &stat);
if (stat.shm_nattch == 0) {
/* if the shm segment is not attached to any
* process, it's a relic that needs to be
* cleaned up before we do anything else. on
* a sane OS, there would be built-in non-
* persistence mechanisms for shared mem, but
* alas, as you already know, POSIX */
shmctl(shm, IPC_RMID, &stat);
goto tryagain;
}
struct signal*s = shmlinux(
mmap(0, sizeof(struct signal), PROT_READ | PROT_WRITE, MAP_SHARED, shm, 0)
) shmsysv (
shmat(shm, 0, 0)
);
if (s == shmlinux(MAP_FAILED) shmsysv((void*)-1))
return bad(fail_mem);
return bad(activate_window(s->wid));
}
} else if (op == mode_register)
return bad(register_window(shmlinux(shid,) init_weak,init_named));
|