xref: /linux/tools/testing/selftests/proc/proc-self-wchan.c (revision 597473720f4dc69749542bfcfed4a927a43d935e)
1ee9294d6SAlexey Dobriyan /*
2ee9294d6SAlexey Dobriyan  * Copyright © 2018 Alexey Dobriyan <adobriyan@gmail.com>
3ee9294d6SAlexey Dobriyan  *
4ee9294d6SAlexey Dobriyan  * Permission to use, copy, modify, and distribute this software for any
5ee9294d6SAlexey Dobriyan  * purpose with or without fee is hereby granted, provided that the above
6ee9294d6SAlexey Dobriyan  * copyright notice and this permission notice appear in all copies.
7ee9294d6SAlexey Dobriyan  *
8ee9294d6SAlexey Dobriyan  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9ee9294d6SAlexey Dobriyan  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10ee9294d6SAlexey Dobriyan  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11ee9294d6SAlexey Dobriyan  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12ee9294d6SAlexey Dobriyan  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13ee9294d6SAlexey Dobriyan  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14ee9294d6SAlexey Dobriyan  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15ee9294d6SAlexey Dobriyan  */
169cd65655SAlexey Dobriyan #include <sys/types.h>
179cd65655SAlexey Dobriyan #include <sys/stat.h>
189cd65655SAlexey Dobriyan #include <fcntl.h>
199cd65655SAlexey Dobriyan #include <errno.h>
209cd65655SAlexey Dobriyan #include <unistd.h>
219cd65655SAlexey Dobriyan 
main(void)229cd65655SAlexey Dobriyan int main(void)
239cd65655SAlexey Dobriyan {
249cd65655SAlexey Dobriyan 	char buf[64];
259cd65655SAlexey Dobriyan 	int fd;
269cd65655SAlexey Dobriyan 
279cd65655SAlexey Dobriyan 	fd = open("/proc/self/wchan", O_RDONLY);
289cd65655SAlexey Dobriyan 	if (fd == -1) {
299cd65655SAlexey Dobriyan 		if (errno == ENOENT)
30*0338c838SAlexey Dobriyan 			return 4;
319cd65655SAlexey Dobriyan 		return 1;
329cd65655SAlexey Dobriyan 	}
339cd65655SAlexey Dobriyan 
349cd65655SAlexey Dobriyan 	buf[0] = '\0';
359cd65655SAlexey Dobriyan 	if (read(fd, buf, sizeof(buf)) != 1)
369cd65655SAlexey Dobriyan 		return 1;
379cd65655SAlexey Dobriyan 	if (buf[0] != '0')
389cd65655SAlexey Dobriyan 		return 1;
399cd65655SAlexey Dobriyan 	return 0;
409cd65655SAlexey Dobriyan }
41