- connection error in unix domain socket implemented in c (gcc) centos 7
- 2 Answers 2
- Глюки при монтировании CIFS Samba
- Can not connect to Linux «abstract» unix socket
- 4 Answers 4
- Why is my machine unable to mount my SMB drives («CIFS VFS: Error connecting to socket. Aborting operation», return code -115)?
- unixforum.org
- Re: Samba
- Re: Samba
- Re: Samba
- Re: Samba
- Re: Samba
- Re: Samba
- Re: Samba
connection error in unix domain socket implemented in c (gcc) centos 7
I have checked the path «/tmp/dsock» and the socket file «dsock» is there but looking inside the file shows:
File: ‘dsock’ Size: 0 Blocks: 0 IO Block: 4096 socket Device: 801h/2049d Inode: 1572866 Links: 1 Access: (0777/srwxrwxrwx) Uid: ( 7418/user) Gid: (25/group) Access: 2017-08-31 17:16:29.569038461 -0600 Modify: 2017-08-31 17:16:29.569038461 -0600 Change: 2017-09-01 13:28:07.162071494 -0600 Birth: -
Can’t find what the error is. The client side also shows similar connection error. Is it due to the UNIX domain socket file permission issues?
The first step in tackling these kind of problems is ALWAYS to see the error that the system returned. Most UNIX system calls will set errno to give specific error details when they return -1 on error. You should: 1) Include errno.h 2) Log detailed error messages using: printf(«Error %d: %s\n», errno, strerror(errno)); This should ideally be done as part of the routine system call error check
2 Answers 2
You cannot call connect on a listening socket. Once you have bound and listened, the only thing you should do with a listening socket is call accept (or close or use its descriptor in a select ).
So the server should create the socket, bind its address, listen on it and then the server should be sitting («blocked») in the accept function. That is, it’s waiting for a connection, usually in a loop.
Then (after the server has been started and is waiting) your client needs to create its own socket and call connect on it — specifying the same address that the server used when it called bind . This will cause the accept call in the server to return a new socket descriptor for a socket that is actually connected to the client. This is the one that you will use send and recv on for communication. (And the client’s socket will also be connected.)
At this point, the listening socket in the server will still be available to accept additional connections (each of which would return its own new unique socket descriptor).
Although possible, it doesn’t really make sense for the server to connect to its own listening socket endpoint anyway. What would be the point?
Глюки при монтировании CIFS Samba
Нужно во первых установить cifs-utils, smbclient и rpcbind.
Во вторых настроить /etc/network/interfaces
А точнее место allow-hotplug поставить auto.
Если /etc/network/interfaces не настроен, как это в убунте. Порнография эта.
То нужно настраивать, потому что может прилететь обновление ядра. И сеть может полностью упасть. Даже через chroot ничего не сделаешь.
PS долго гуглил. Не нашёл ответа и вот научным тыком добился стабильности.
Samba монтировалась через fstab как ей по кайфу. Могла монтироваться, а могла и нет.
А если сеть не упадёт, то, в принципе, через chroot можно будет порнографию сделать?
Знатоки systemd, а что надо было сделать вместо сабжа, чтобы маунтпойнту добавить зависимость на поднятие конкретного интерфейса?
Нужно во первых установить cifs-utils, smbclient и rpcbind.
Во вторых настроить /etc/network/interfaces
А точнее место allow-hotplug поставить auto.
Если /etc/network/interfaces не настроен, как это в убунте. Порнография эта.
По моему порнография — это этот мануал. Подозреваю, что проблема в том что samba-ресурс из fstab не может смонтироваться на этапе загрузки системы т.к. сетевой интерфейс еще не готов. Так делать не нужно. Гораздо надежнее настроить подключение samba-ресурса по запросу к каталогу в который настроено монтирование данного ресурса (под запросом я имею ввиду просто открытие данного каталога). Я раньше использовал для этого autofs , сейчас может это еще актуально, а может что-то новое придумано.
rumgot ★★★★★ ( 14.12.20 00:04:44 MSK )
Последнее исправление: rumgot 14.12.20 00:08:58 MSK (всего исправлений: 3)
Это не надежно. А вдруг в процессе работы сеть отрубится при том, что фактически ресурс не используется пользователем? Может быть зависание системы. Лучше монтирование по запросу к каталогу (под запросом я имею ввиду просто открытие данного каталога).
rumgot ★★★★★ ( 14.12.20 00:07:14 MSK )
Последнее исправление: rumgot 14.12.20 00:08:37 MSK (всего исправлений: 1)
Can not connect to Linux «abstract» unix socket
I’m trying to use UNIX sockets for inter-thread communication. The program is only intended to run on Linux. To avoid creating the socket files, I wanted to use «abstract» sockets, as documented in unix(7). However, I don’t seem to be able to connect to these sockets. Everything works if I’m using «pathname» sockets, though. Here is the code (I haven’t quoted any error handling, but it’s done): thread#1:
int log_socket = socket(AF_LOCAL, SOCK_STREAM, 0); struct sockaddr_un logaddr; socklen_t sun_len = sizeof(struct sockaddr_un); logaddr.sun_family = AF_UNIX; logaddr.sun_path[0] = 0; strcpy(logaddr.sun_path+1, "futurama"); bind(log_socket, &logaddr, sun_len); listen(log_socket, 5); accept(log_socket, &logaddr, &sun_len); . // send - receive
struct sockaddr_un tolog; int sock = socket(AF_LOCAL, SOCK_STREAM, 0); tolog.sun_family = AF_UNIX; tolog.sun_path[0] = 0; strcpy(tolog.sun_path+1, "futurama"); connect(sock, (struct sockaddr*)&tolog, sizeof(struct sockaddr_un));
If all I do in the above code, is change the sun_path to not have leading \0, things work perfect. strace output:
t1: socket(PF_FILE, SOCK_STREAM, 0) = 0 t1: bind(0, , 110) t1: listen(0, 5) t2: socket(PF_FILE, SOCK_STREAM, 0) = 1 t2: connect(1, , 110 t2: ) = -1 ECONNREFUSED (Connection refused) t1: accept(0,
I know that the connect comes before accept, that’s not an issue (I tried making sure that accept() is called before connect(), same result. Also, things are fine if the socket is «pathname» anyway).
For communication between threads of the same process, an ordinary pipe(2) should be enough! And you could also use pipes if all the communicating processes and/or threads have the same parent process!
@BasileStarynkevitch pipe will not work in my case. I need multiple threads to send info, and receive a synchronous response before moving on.
@BasileStarynkevitch for this, I will have to know in advance how many maximum pipes to open, or limit access to one using locks. The socket approach has less overhead for such case.
4 Answers 4
While I was posting this question, and re-reading unix(7) man page, this wording caught my attention:
an abstract socket address is distinguished by the fact that sun_path[0] is a null byte (’\0’). All of the remaining bytes in sun_path define the «name» of the socket
So, if I bzero’ed the sun_path before filling in my name into it, things started to work. I figured that’s not necessarily straight-forward. Additionally, as rightfully pointed out by @davmac and @StoneThrow, the number of those «remaining bytes» can be reduced by specifying only enough length of the socket address structure to cover the bytes you want to consider as your address. One way to do that is to use SUN_LEN macro, however, the first byte of the sun_path will have to be set to !0, as SUN_LEN uses strlen .
If sun_path[0] is \0, The kernel uses the entirety of the remainder of sun_path as the name of the socket, whether it’s \0-terminated or not, so all of that remainder counts. In my original code I would zero the first byte, and then strcpy() the socket name into the sun_path at position 1. Whatever gibberish that was in sun_path when the structure was allocated (especially likely to contain gibberish since it’s allocated on the stack), and was included in the length of the socket structure (as passed to the syscalls), counted as the name of the socket, and was different in bind() and connect().
IMHO, strace should fix the way it displays abstract socket names, and display all the sun_path bytes from 1 to whatever the structure length that was supplied, if sun_path[0] is 0
Why is my machine unable to mount my SMB drives («CIFS VFS: Error connecting to socket. Aborting operation», return code -115)?
I have a machine running Precise (12.04 x64), and I cannot mount my SMB drives. It used to work (a week or two ago) and I didn’t touch fstab! The machine hosting the shares is a commercial NAS, and I’m not seeing anything that would indicate it’s an issue with the NAS. I have an older machine which I updated to Precise at the same time (both fresh installed, not dist-upgrade), so should have a very similar configuration. It is not having any problems. I am not having problems on windows machines/partitions either, only one of my Precise machines. The two machines are using identical entries in fstab and identical /etc/samba/smb.conf files. I don’t think I’ve ever changed smb.conf (has never mattered before). My fstab entries all basically look like this:
// /media/ cifs credentials=/home/downbeat/.credentials,iocharset=utf8,uid=downbeat,gid=downbeat,file_mode=0644,dir_mode=0755 0 0
[ 51.162198] CIFS VFS: Error connecting to socket. Aborting operation [ 51.162369] CIFS VFS: cifs_mount failed w/return code = -115 [ 51.194106] CIFS VFS: Error connecting to socket. Aborting operation [ 51.194250] CIFS VFS: cifs_mount failed w/return code = -115 [ 51.198120] CIFS VFS: Error connecting to socket. Aborting operation [ 51.198243] CIFS VFS: cifs_mount failed w/return code = -115
There are no other errors I see in the dmesg output. Again, it used to work; now it doesn’t. Very similarly configured machine works (but some packages are out of date on the working machine). The NAS has only one interface/IP address, nmblookup works to find it’s IP from it’s hostname (from the machine with the issue) and it responds to a ping. Please any help would be great.
unixforum.org
ubuntu 9.10
На клиентской тачке (ubuntu) установил самбу, расшарил папку. На другом серваке (ubuntu) пытаюсь сделать:
mount -t smbfs //IP/dir /mnt/dir -o -username=xxx,password=xxx
После чего получаю сообщения:
CIFS VFS: Error connecting to socket. Aborting operation. CIFS VFS: cifs_mount failed w/return code = -22
В чем проблема? Пробовал вместо smbfs, civfs не помогает.
Re: Samba
Сообщение guliver » 28.04.2010 15:24
Re: Samba
Re: Samba
Сообщение BigBrother » 28.04.2010 18:03
mount.cifs и mount.smbfs не помогают — такая же ошибка
Re: Samba
$ sudo apt-get install smbfs
$ sudo mount -t cifs -o username=XXX //ip/share /mnt/point
пароль в опциях не задавайте.
Ошибка -22 — значит неверный аргумент.
Re: Samba
Сообщение BigBrother » 28.04.2010 18:33
CIFS VFS: Error connecting to socket. Aborting operation. CIFS VFS: cifs_mount failed w/return code = -113 CIFS VFS: Error connecting to socket. Aborting operation. CIFS VFS: cifs_mount failed w/return code = -512
Re: Samba
Re: Samba
Сообщение BigBrother » 28.04.2010 19:07
упс, пардон. При монтировании оказалось что имя хоста не соответствует !Р и соответственно не возможно было найти нужную папку. Команда mount -t cifs //!Р/дир /mnt/дир -o username=test,password=test сработало нормально.
Но теперь, появился другой вопрос. Когда, я копирую /home/dir/archive.tar в /mnt/dir (эта папка на другом компе) я получаю в конце копирования сообщение:
Невозможно сменить владельца целевого файла "/mnt/dir/archive.tar Permission denied (13)
Жму «пропустить». Захожу в папку на хосте куда копировал, там архив появился и я могу его распаковать.
Папка расшарена по самбе под паролем. Владелец папки и пароль указываю когда монтирую на другом хосте. Права на папку, которая расшарена 775 с опцией -R. Владелец соответственно выставлен.
После копирования, и пропуска ошибки, файл создается с правами -rw-r—r—