Skip to content

hostconfig: Use make_path to create possible non-existing directory /node #184

Merged
merged 1 commit into from
Jan 3, 2023

Conversation

pmenzel
Copy link
Contributor

@pmenzel pmenzel commented May 6, 2021

No description provided.

@donald
Copy link
Collaborator

donald commented May 6, 2021

Did you test that? I think, make_path is from some module.
Sigh, this node thing is an ugly, obsolete hack. I hoped to get rid of it.
Strange design of systemd to fail on an "exists"-test if a parent doesn't exist. I'd say, the answer "no" would be more sensible. Maybe I create an issue for that, if that hasn't been on the table yet.

@pmenzel
Copy link
Contributor Author

pmenzel commented May 7, 2021

Did you test that? I think, make_path is from some module.

No, I didn’t. I definitely tagged to need more testing. No idea, why GitHub didn’t add it.

Sigh, this node thing is an ugly, obsolete hack. I hoped to get rid of it.

Sounds good.

Strange design of systemd to fail on an "exists"-test if a parent doesn't exist. I'd say, the answer "no" would be more sensible. Maybe I create an issue for that, if that hasn't been on the table yet.

Sorry, what do you mean. hostconfig --populate-node fails.

hostconfig[1297907]: /node/tags: No such file or directory
systemd[1]: startup-tags.service: Main process exited, code=exited, status=2/INVALIDARGUMENT

@donald
Copy link
Collaborator

donald commented May 7, 2021

Sorry, what do you mean. hostconfig --populate-node fails.

My bad. I was missreading that from a mobile.

btw: system 'mkdir', '-p', $DIR and exit 1; would also be an option and would avoid to use an addition perl module.

@wwwutz
Copy link
Contributor

wwwutz commented May 17, 2021

sub mkdirp {
  my $d = shift;
  my $dtc = '';
  foreach my $sd ( split(/\//,$d) ) {
     ($sd eq '') and $sd = '/';
     $dtc .= $sd;
     if ( ! -d $dtc ) {
         mkdir($dtc) or return $!;
     }
     $dtc .= '/';
  }
  return 1;
}

@donald
Copy link
Collaborator

donald commented May 17, 2021

@wwwutz: return $! .vs. return 1. If you return errno value for failure, maybe return 0 for success.

@wwwutz
Copy link
Contributor

wwwutz commented May 17, 2021

zero, false, $? ... 8-) it's just an example, feel free to change. At least it doesn't load shared libs 8-))))
and it does not want to mkdir -p anything else than a path. not user-input-save. but enough for mkdirp('/node/foobar').

will certainly fail on ../../../././../\rm, -rf`\ /\\ \ ` " \'''``\ \0\0\

hehe... but... hey.. we're talking about mkdir('/node/foobar') in hostconfig ... not netcat -l -p 80 | sudo

@donald
Copy link
Collaborator

donald commented May 18, 2021

../../../././../\rm, -rf\ /\\ \ " '''``\ \0\0\

Hmmm, that should actually work. If \0 refers to the two-character sequence backslash and digit zero no surprise. If, on the other hand, '\0' refers to a character encoded with as a binary zero byte, mkdir(2) would try to create a directory ../../../././../\rm, -rf\ /\ \ " \'''``\ which might or might not be what was intended. And if backslash+character was used to indicate a special single character here, the meaning of the lonely backslash character at the end would need to be defined.

How about mkdir "\e[2J" ? If you cd into that directory, you will always have a nicely cleaned up screen (if your shell prompt includes the cwd). Do Terminal emulators nowadays still allow to redefined keys via escape sequences? Create a directory "This_is_a_vary_long_directory_dont_look_into_it" concatenated with the escape sequence to redefine the enter key to rm -rf / and wait until a nosy and lazy root uses cd This<TAB> to get into it :-)

…`/node`

    # systemctl status startup-tags.service
    ● startup-tags.service
         Loaded: loaded (/etc/systemd/system/startup-tags.service; static)
         Active: failed (Result: exit-code) since Thu 2021-05-06 20:46:29 CEST; 4min 11s ago
        Process: 1297907 ExecStart=/usr/sbin/hostconfig --populate-node (code=exited, status=2)
       Main PID: 1297907 (code=exited, status=2)

    May 06 20:46:29 flughafenberlinbrandenburgwillybrandt systemd[1]: Starting startup-tags.service...
    May 06 20:46:29 flughafenberlinbrandenburgwillybrandt hostconfig[1297907]: /node/tags: No such file or directory
    May 06 20:46:29 flughafenberlinbrandenburgwillybrandt systemd[1]: startup-tags.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
    May 06 20:46:29 flughafenberlinbrandenburgwillybrandt systemd[1]: startup-tags.service: Failed with result 'exit-code'.
    May 06 20:46:29 flughafenberlinbrandenburgwillybrandt systemd[1]: Failed to start startup-tags.service.
@donald donald force-pushed the hostconfig-also-create-node-directory branch from 70ebde0 to 73a2922 Compare December 7, 2022 10:18
@donald donald merged commit 4bc27d6 into master Jan 3, 2023
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants