toolbox

Check-in [581d07e392]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:i3notify: fix openbsd write bug
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:581d07e392408e6110b925f0b1fa8d73177b1182815180d987cbd1c24b324e4e
User & Date: jef 2019-02-24 19:16:18
Context
2019-02-24
19:37
lib: make Makefile openbsd compatible check-in: 50551a9e8c user: jef tags: trunk
19:16
i3notify: fix openbsd write bug check-in: 581d07e392 user: jef tags: trunk
19:14
xtypekeys: fix openbsd co;pilation check-in: 00b8c871a0 user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/i3notify/i3notify.c.

86
87
88
89
90
91
92


93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
186
187
188
189
190
191
192

193
194
195
196
197
198
199
...
202
203
204
205
206
207
208


209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
		die("socket filename too long");
	strncpy(addr->sun_path, path, strlen(path));
}

void
socket_write(int fd, char *msg)
{


	if (write(fd, msg, strlen(msg)) < (ssize_t) strlen(msg))

		die("write error:");
}

void
socket_dump(int fd)
{
	char buf[1024];
	int nread, nwrite;

	while ((nread = read(fd, buf, sizeof(buf))) > 0) {
		nwrite = write(STDOUT_FILENO, buf, nread);
		if (nwrite != nread)
			die("write error:");
	}
	if (nread == -1)
................................................................................
		die("read error:");
}

void
server_client_handle(int clientfd)
{
	char buf[1024], *msg;
	int rc;

	rc = read(clientfd, buf, sizeof(buf));
	if (rc == sizeof(buf)) {
		warning("too long request from client");
		return;
	}
	buf[rc] = '\0';
................................................................................
	return fd;
}

int
main(int argc, char *argv[])
{
	int ch, serverfd;


	while ((ch = getopt(argc, argv, "hs")) != -1) {
		switch (ch) {
		case 'h':
			usage();
			break;
		case 's':
................................................................................
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 1)
		die("not enough arguments");



	serverfd = client_connect();
	if (strcmp(argv[0], "push") == 0) {
		if (argc != 2)
			die("wrong number of arguments");
		socket_write(serverfd, argv[0]);
		socket_write(serverfd, argv[1]);

	} else if (strcmp(argv[0], "pop") == 0) {
		socket_write(serverfd, argv[0]);
		socket_dump(serverfd);
	} else {
		die("invalid command '%s'", argv[0]);
	}
	close(serverfd);

	return EXIT_SUCCESS;
}







>
>
|
>







|







 







|







 







>







 







>
>





|
|
>










86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
		die("socket filename too long");
	strncpy(addr->sun_path, path, strlen(path));
}

void
socket_write(int fd, char *msg)
{
	ssize_t nwrite;

	nwrite = write(fd, msg, strlen(msg));
	if (nwrite < (ssize_t) strlen(msg))
		die("write error:");
}

void
socket_dump(int fd)
{
	char buf[1024];
	ssize_t nread, nwrite;

	while ((nread = read(fd, buf, sizeof(buf))) > 0) {
		nwrite = write(STDOUT_FILENO, buf, nread);
		if (nwrite != nread)
			die("write error:");
	}
	if (nread == -1)
................................................................................
		die("read error:");
}

void
server_client_handle(int clientfd)
{
	char buf[1024], *msg;
	ssize_t rc;

	rc = read(clientfd, buf, sizeof(buf));
	if (rc == sizeof(buf)) {
		warning("too long request from client");
		return;
	}
	buf[rc] = '\0';
................................................................................
	return fd;
}

int
main(int argc, char *argv[])
{
	int ch, serverfd;
	char *buf = NULL;

	while ((ch = getopt(argc, argv, "hs")) != -1) {
		switch (ch) {
		case 'h':
			usage();
			break;
		case 's':
................................................................................
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 1)
		die("not enough arguments");

	signal(SIGPIPE, SIG_IGN);

	serverfd = client_connect();
	if (strcmp(argv[0], "push") == 0) {
		if (argc != 2)
			die("wrong number of arguments");
		xasprintf(&buf, "%s%s", argv[0], argv[1]);
		socket_write(serverfd, buf);
		xfree(buf);
	} else if (strcmp(argv[0], "pop") == 0) {
		socket_write(serverfd, argv[0]);
		socket_dump(serverfd);
	} else {
		die("invalid command '%s'", argv[0]);
	}
	close(serverfd);

	return EXIT_SUCCESS;
}