On 8/26/21 6:43 AM, Martin Pitt wrote:
Hello Mark,
Mark Reynolds [2021-08-25 12:38 -0400]:
> This code used to work for a long time, but now it stopped working as
> expected:
>
> let cmd = [
> "/bin/sh",
> "-c",
I can't possibly believe that ' vs. " has any actual influence about it --
this
makes absolutely no difference in JavaScript, as per spec [1]. This must be a
red herring.
I agree, yet that's what I saw (and others on my team). It was driving
me nuts, and it was just a coincidence that I made the quotes uniform.
And sorry I kind of added sudo code to this email, but it was an example
that I had tried in the code.
Anyway I'm not sure how much time i want to invest in this since it's
working now, but here is the entire code block before I made the quotes
the same:
let cmd = [
"/bin/sh",
"-c",
'/usr/bin/echo -e "' +
setup_inf + '" >> ' + setup_file
];
// Do not log inf file as
it contains the DM password
log_cmd("createInstance", "Apply changes to INF file...",
"");
cockpit
.spawn(cmd, {
superuser: true, err: "message" })
.fail(err => {
this.setState({
loadingCreate: false
});
addNotification(
"error",
`Failed to populate installation file! ${err.message}`
);
})
.done(_ => {
/*
* Next, create
the instance...
*/
let cmd =
["dscreate", "-j", "from-file", setup_file];
log_cmd("createInstance", "Creating instance...", cmd);
cockpit
.spawn(cmd, {
superuser: true,
err: "message"
})
.fail(err => {
let
errMsg = JSON.parse(err);
cockpit.spawn(rm_cmd, { superuser: true }); // Remove Inf file with
clear text password
this.setState({
loadingCreate: false
});
addNotification(
"error",
`${errMsg.desc}`
);
})
.done(_ => {
//
Success!!! Now cleanup everything up...
log_cmd("createInstance", "Instance creation compelete, clean everything
up...", rm_cmd);
cockpit.spawn(rm_cmd, { superuser: true }); // Remove Inf file with
clear text password
this.setState({
loadingCreate: false
});
loadInstanceList(createServerId);
addNotification(
"success",
`Successfully created instance: slapd-${createServerId}`
);
closeHandler();
this.resetModal();
});
});
});
I got no errors, and it moved on to the next spawn() command and it
attempted the instance installation even thought the setup file was
empty. We've been using this code for almost two years now, and then it
just started failing for us. Then all I did was change the quotes and
it started working again. Very odd and it doesn't make any sense to me
either...
For completeness, the "setup_inf" variable contained:
[general]
config_version = 2
full_machine_name = localhost.localdomain
start = True
[slapd]
port = 389
root_dn = cn=dm
root_password = Secret123
[backend-userroot]
sample_entries = yes
suffix = dc=example,dc=com
No special characters or quotes, or anything out of place.
One thing I am on F34 not F33, not sure if that makes a difference or
not. And I am on Cockpit 250...
Thanks,
Mark
> '/usr/bin/echo TEST >> ' + setup_file
Is it possible that setup_file contains quotes?
> cockpit.spawn (cmd, { superuser: true, err: "message" })
Are you actually waiting for this promise to settle? I.e. did you remove the
.then/.catch only to shorten your email, or are they actually missing in your
code?
In a running Cockpit session, I opened the developer console and ran
cockpit.spawn(['/bin/sh', '-c', '/usr/bin/echo TEST >>
/tmp/my_file'], { superuser: true, err: "message"}).then(() =>
console.log("success")).catch(e => console.error(e))
This works, logs "succcess", and I have a root-owned /tmp/my_file with
"TEST"
in it. You can try the same -- that's much more convenient than having to
re-build a script and reloading the page.
If your promise handlers are missing, can you try to add them and see what they
complain about?
> Now the output file (setup_file) is empty.
Does it get created, or is a leftover from a previous run? I.e. try to remove
it first, to see if the shell at least gets that far, or if it already aborts
ealier on. It may be a permission error (although unlikely as it runs as root,
but there's always SELinux and such -- the rejection message will tell you).
Another possible gotcha might be that you did not elevate to sudo privileges in
your cockpit session, so the spawn call would fail (it has `superuser: true`).
Again, the rejection message will tell you.
Martin
[1]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_...
_______________________________________________
cockpit-devel mailing list -- cockpit-devel(a)lists.fedorahosted.org
To unsubscribe send an email to cockpit-devel-leave(a)lists.fedorahosted.org
Fedora Code of Conduct:
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines:
https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives:
https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedoraho...
Do not reply to spam on the list, report it:
https://pagure.io/fedora-infrastructure
--
Directory Server Development Team