no-op refactoring: make ipc_connect find socket path
This commit is contained in:
@ -55,10 +55,6 @@ static yajl_callbacks version_callbacks = {
|
||||
*
|
||||
*/
|
||||
void display_running_version(void) {
|
||||
char *socket_path = root_atom_contents("I3_SOCKET_PATH", conn, conn_screen);
|
||||
if (socket_path == NULL)
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
char *pid_from_atom = root_atom_contents("I3_PID", conn, conn_screen);
|
||||
if (pid_from_atom == NULL) {
|
||||
/* If I3_PID is not set, the running version is older than 4.2-200. */
|
||||
@ -71,18 +67,7 @@ void display_running_version(void) {
|
||||
printf("(Getting version from running i3, press ctrl-c to abort…)");
|
||||
fflush(stdout);
|
||||
|
||||
/* TODO: refactor this with the code for sending commands */
|
||||
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
if (sockfd == -1)
|
||||
err(EXIT_FAILURE, "Could not create socket");
|
||||
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
|
||||
if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
|
||||
err(EXIT_FAILURE, "Could not connect to i3");
|
||||
|
||||
int sockfd = ipc_connect(NULL);
|
||||
if (ipc_send_message(sockfd, 0, I3_IPC_MESSAGE_TYPE_GET_VERSION,
|
||||
(uint8_t *)"") == -1)
|
||||
err(EXIT_FAILURE, "IPC: write()");
|
||||
@ -184,5 +169,4 @@ void display_running_version(void) {
|
||||
yajl_free(handle);
|
||||
free(reply);
|
||||
free(pid_from_atom);
|
||||
free(socket_path);
|
||||
}
|
||||
|
Reference in New Issue
Block a user