Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix daemon and python 3.7 issues #150

Conversation

gonzoleeman
Copy link
Contributor

Fixed targetcli/targetclid interaction, both with and without systemd.

Tested on 5.3 kernel, and with python 3.7, 4.12 kernel with python 3.6.5.

The indentation was wrong, causing the daemon to only
process the very last line of outout.
We can no longer have python automatically convert
binary to/from string data, so be explicit about it.

Also, the TargetCLI __del__ method was testing for a
non-existant attribute.
There's no need to reply when we have a zero-byte message.
Before being fixed, this caused a hang when shutting down.
Save the error exit for unknown exits. This makes
systemd happier, since it stops us with a signal.
This allows the main loop to get an exception. Before this, stopping
the daemon required sending a KILL signal or sending one last
command, so that the loop could check the "received a signal" flag.
Regular socket communications are fallen back to when
no systemd socket is present.
The 'exit' command returns nothing, but we must return
at least that blank response to make targetcli happy.
Before, we would get a "Bad File Descriptor" message when
a signal causes closure of the socket while waiting on a
socket message.
Copy link
Contributor

@pkalever pkalever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have tested the series, the unix sock activation works as expected now.

Thank you very much @gonzoleeman I have now understand which piece is missing :-)

And thanks for correcting all the indentations. What I like most are those short and crisp cuts of various patches and good commit messages :-)

Adding few minor review comments.

After=network.target targetclid.socket
Requires=targetclid.socket
Documentation=man:targetcli(8)
After=network.target targetcli.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be you mean targetclid.socket ?

@@ -92,8 +92,7 @@ class TargetCLI:
'''
destructor
'''
if not self.pfd.closed:
self.pfd.close()
self.pdf.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be s/pdf/pfd/ ?

and may be, I was thinking something like:

if self.pfd:
    self.pdf.close()

@@ -92,7 +92,7 @@ class TargetCLI:
'''
destructor
'''
self.pdf.close()
self.pfd.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you fixed the typo here, instead may be you want to merge this patch to patch with title "Handle Python 3.7 stricter binary vs. string rules."

@@ -225,6 +228,7 @@ def main():
to.display(to.render(err.strerror, 'red'))
sys.exit(1)

to.sock = sock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch :-)

Can we assign it as soon as it is created ? may be at line 216 ?

@@ -164,9 +164,9 @@ class TargetCLI:

with open('/tmp/data.txt', 'r') as f:
output = f.read()
var = struct.pack('i', len(output))
connection.sendall(var) # length of string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be club this patch with patch with subject "Only return response to targetcli when bytes present"

@gonzoleeman
Copy link
Contributor Author

gonzoleeman commented Oct 10, 2019 via email

@pkalever
Copy link
Contributor

No, I do not. It does not need to be told to start after targetclid.socket.

In SUSE we have targetcli.service, which manages the targetcli configuration persistence. I will be proposing that same service file for targetcli-fb soon, but for you it doesn’t exist yet. Which means this “After” doesn’t hurt anything.

I can remove it, for now, if you wish.

Ah! okay. Yes, for now IMO it will be confusing for users/readers when they cat the targetclid.service file and see something that is not part of installation.

May be for now you can have a wrapper service in suse project which should import targetclid.service and play your stuff there ?

I believe calling close() on an FD that is not open is not an exception, but I may be wrong.

Yeah, my intention was to just follow any uniform style within this file at-least, example we used,

if self.sock:
    self.sock.close()

I'm okay with both the ways.

Yes. But note that I created the “to.sock” attribute, so that it can be closed when we receive a signal, thus ending the listening loop.

Not sure, if I was able to put my intention correctly before, what I meant was, lets assign sock to to.sock attribute as soon as sock is created (at 216 ?), so that if the signal is received before current assignement (before entering the listening loop) the socket will be closed in the sig handler.

Rest of my comments are not mandatory, but if you are re-spinning the series, feel free to consider or drop them as per your choice :-)

Thanks!

@gonzoleeman
Copy link
Contributor Author

I am submitting an updated pull request, so I'm closing this one.

@gonzoleeman gonzoleeman deleted the fix-daemon-and-python-3.7-issues branch February 18, 2020 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants