2020-08-01 23:49:01 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, the SerenityOS developers.
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 23:49:01 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-08-25 17:48:11 +03:00
|
|
|
#include <AK/Assertions.h>
|
2021-05-14 16:32:57 +02:00
|
|
|
#include <errno.h>
|
2020-01-19 01:04:48 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
int main(int, char**)
|
|
|
|
|
{
|
2022-04-01 20:58:27 +03:00
|
|
|
constexpr char const* path = "/tmp/foo";
|
2020-01-19 01:04:48 +03:00
|
|
|
int rc = symlink("bar", path);
|
|
|
|
|
if (rc < 0) {
|
|
|
|
|
perror("symlink");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
|
if (fd < 0) {
|
|
|
|
|
perror("socket");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
|
addr.sun_family = AF_UNIX;
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(strlcpy(addr.sun_path, path, sizeof(addr.sun_path)) < sizeof(addr.sun_path));
|
2020-01-19 01:04:48 +03:00
|
|
|
|
|
|
|
|
rc = bind(fd, (struct sockaddr*)(&addr), sizeof(addr));
|
2020-08-01 23:49:01 +02:00
|
|
|
if (rc < 0 && errno == EADDRINUSE) {
|
|
|
|
|
printf("PASS\n");
|
2020-01-19 01:04:48 +03:00
|
|
|
return 0;
|
2020-08-01 23:49:01 +02:00
|
|
|
}
|
2020-01-19 01:04:48 +03:00
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|