A friend of mine was replacing the motherboard in his Dell with newer, faster, OEM motherboard. However, he couldn't get the power button, and other front-panel stuff, to work -- the connectors were different sizes, with different pin layouts. I took a bunch of spare jumpers and spare wires, and connected the proper pins one by one. No soldering needed :)
Code-wise, I'm constantly being impressed. I always thought there was no elegant way of determining whether a fork
ed child successfully exec
ed, but there actually is.
child:
execvp(argv[0], argv);
errval = errno;
write(data->fd, &errval, sizeof(errval));
parent:
socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
flag = fcntl(fds[1], F_GETFD) | FD_CLOEXEC;
fcntl(fds[1], F_SETFD, flag);
pid = clone(child, NULL, SIGCHLD, NULL);
if(pid < 0){
...
}
close(fds[1]);
/* Read the errno value from the child, if the exec failed, or get 0 if
* the exec succeeded because the pipe fd was set as close-on-exec.
*/
n = read(fds[0], &ret, sizeof(ret));
if (n < 0) {
...
} else if(n != 0){
/* exec failed */
} else {
/* exec succeeded */
}