util  Check-in [33d1991a4d]

Overview
Comment:fix longstanding and COMPLETELY IDIOTIC bugs in xpriv. how fucking high was i when i wrote this shit!???
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 33d1991a4dae045b02de707f5cdff1d0f19e3fd45ef08fd1bbdddb5bb9d13747
User & Date: lexi on 2019-08-08 00:09:30
Other Links: manifest | tags
Context
2019-08-13
02:28
add missing --nocopy option to mkpw check-in: 61813b7d9b user: lexi tags: trunk
2019-08-08
00:09
fix longstanding and COMPLETELY IDIOTIC bugs in xpriv. how fucking high was i when i wrote this shit!??? check-in: 33d1991a4d user: lexi tags: trunk
2019-08-07
09:47
add further wrappings to nkvd.c; nearly works with alpine now check-in: dc9aa070c7 user: lexi tags: trunk
Changes

Modified xpriv.c from [48a3d17a7c] to [7043c5d202].

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));