From: "Maxim Melentiev" <dmarc-noreply@freelists.org> (Redacted sender "m.melentiev" for DMARC)
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org, alexander.turenko@tarantool.org
Subject: [tarantool-patches] Re: [PATCH] Replace sendmsg with sendto shortcut
Date: Tue, 20 Aug 2019 15:16:35 +0300 [thread overview]
Message-ID: <685c8df1-3ebb-07d7-44ba-2c79dce115c9@corp.mail.ru> (raw)
In-Reply-To: <20190820120102.60158-1-m.melentiev@corp.mail.ru>
ping Konstantin Osipov, Alexander Turenko
Sorry, forgot to CC in initial email and then pinged in wrong thread.
On 20/08/2019 15:01, Max Melentiev (Redacted sender m.melentiev for
DMARC) wrote:
> There is a problem with calculating .msg_namelen field
> of msghdr struct. Instead of
>
> .msg_name = &sa,
> .msg_namelen = sizeof(sa.sun_family) + strlen(sd_unix_path),
>
> it must set as
>
> .msg_namelen = sizeof(sa) // larger value than current invalid one
>
> It works on linux but when I tried to enable this feature for macOS
> it didn't (maybe because of different order of fields in the struct).
>
> Instead of fixing calculation, I've replaced original sendmsg call
> with sendto, because it's a convenient shortcut which
> simplifies code and can prevent such mistakes.
> ---
>
> Preview: https://github.com/printercu/tarantool/commit/bc30b1093be1d03507bf84ca218b03bec5e0244a
>
> src/systemd.c | 13 ++-----------
> 1 file changed, 2 insertions(+), 11 deletions(-)
>
> diff --git a/src/systemd.c b/src/systemd.c
> index b6c48afe2..9c0a26dd2 100644
> --- a/src/systemd.c
> +++ b/src/systemd.c
> @@ -100,23 +100,14 @@ int systemd_notify(const char *message) {
> struct sockaddr_un sa = {
> .sun_family = AF_UNIX,
> };
> - struct iovec vec = {
> - .iov_base = (char *)message,
> - .iov_len = (size_t )strlen(message)
> - };
> - struct msghdr msg = {
> - .msg_iov = &vec,
> - .msg_iovlen = 1,
> - .msg_name = &sa,
> - };
>
> - msg.msg_namelen = sizeof(sa.sun_family) + strlen(sd_unix_path);
> strncpy(sa.sun_path, sd_unix_path, sizeof(sa.sun_path));
> if (sa.sun_path[0] == '@')
> sa.sun_path[0] = '\0';
>
> say_debug("systemd: sending message '%s'", message);
> - ssize_t sent = sendmsg(systemd_fd, &msg, MSG_NOSIGNAL);
> + ssize_t sent = sendto(systemd_fd, message, (size_t)strlen(message),
> + MSG_NOSIGNAL, (struct sockaddr*)&sa, sizeof(sa));
> if (sent == -1) {
> say_syserror("systemd: failed to send message");
> return -1;
> --
> 2.21.0
>
>
> .
>
next prev parent reply other threads:[~2019-08-20 12:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-20 12:01 [tarantool-patches] " Max Melentiev
2019-08-20 12:16 ` Maxim Melentiev [this message]
2019-08-20 23:34 ` [tarantool-patches] " Alexander Turenko
2019-08-21 8:23 ` Maxim Melentiev
2019-08-21 10:02 ` Alexander Turenko
2019-08-20 13:06 ` Konstantin Osipov
2019-08-22 13:15 ` Kirill Yukhin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=685c8df1-3ebb-07d7-44ba-2c79dce115c9@corp.mail.ru \
--to=dmarc-noreply@freelists.org \
--cc=alexander.turenko@tarantool.org \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='[tarantool-patches] Re: [PATCH] Replace sendmsg with sendto shortcut' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox