Skip to content

u/Commod0re

In this archive from Apr 2014 to Mar 2020

3
posts
131
comments
3
media
581
score

doesn't matter that it's a python script, it's treated the same by the shell. Here's a C program showing the same result:

$ cat test.c
#include <stdio.h>

int main(int argc, const char* argv[]) {
	for (int i = 0; i < argc; ++i) {
		printf("arg %d: %s\n", i, argv[i]);
	}
	return 0;
}
$ gcc -std=gnu99 ./test.c -o test
$ ./test /*
arg 0: ./test
arg 1: /app
arg 2: /bin
arg 3: /boot
arg 4: /cdrom
arg 5: /dev
arg 6: /etc
arg 7: /home
arg 8: /initrd.img
arg 9: /initrd.img.old
arg 10: /lib
arg 11: /lib64
arg 12: /lost+found
arg 13: /media
arg 14: /mnt
arg 15: /opt
arg 16: /proc
arg 17: /root
arg 18: /run
arg 19: /sbin
arg 20: /snap
arg 21: /srv
arg 22: /sys
arg 23: /tmp
arg 24: /usr
arg 25: /var
arg 26: /vmlinuz
arg 27: /vmlinuz.old

one way to change that is to use quotes or otherwise escape the *

$ ./test "/*"
arg 0: ./test
arg 1: /*
$ ./test /\*
arg 0: ./test
arg 1: /*

another is to disable shell globbing:

$ set -f
$ ./test /*
arg 0: ./test
arg 1: /*

I even tried it in an archlinux docker container, as you insisted, and it did exactly what I told you it would do lol

9 points
$ cat test.py 
#!/usr/bin/env python
import sys
print(sys.argv)
$ ./test.py /*
['./test.py', '/app', '/bin', '/boot', '/cdrom', '/dev', '/etc', '/home', '/initrd.img', '/initrd.img.old', '/lib', '/lib64', '/lost+found', '/media', '/mnt', '/opt', '/proc', '/root', '/run', '/sbin', '/snap', '/srv', '/sys', '/tmp', '/usr', '/var', '/vmlinuz', '/vmlinuz.old']

just ran this on my machine from bash, zsh, and sh, and they all produced the same results, expanding the /* before executing test.py

7 points

Anyone with a brain knows that it's commented out and is harmless

however, it's in a field that's meant to be machine-parseable, as in removed from the comment. Given the right (or very wrong, depending on your point of view) circumstances, bash or perl, for examples, could mistakenly interpret those backticks and execute the subshell

The chances of this happening in reality are remote, but intentionally putting injection attacks into things, even as a joke, is still irresponsible at best, and arguably even violates the submission guidelines.

7 points

Fair enough. I mainly brought up POSIX signals in response to the person I was responding to directly, but then it felt like we may have been going off the rails, so I just wanted to be sure

I lightly tested /u/katie-is-gay's wmctrl solution and it's a good starting point. It looks possible to "trick" the script into waiting possibly forever if you open new programs while firefox or libreoffice are waiting for you to click confirm, but it shouldn't be too hard to either avoid that situation entirely, or flesh the script out a little more to account for that.

Good luck!

2 points

SIGINT is actually what CTRL+C sends to the foreground process in a terminal, and for the most part cli programs handle it gracefully. It's not a "something bad happened" it's a "you are being interrupted". It usually gets handled the same as SIGTERM, which is to say, either no handling and process death, or a basic graceful quit, but some GUI toolkits handle this poorly by default.

However, systemd shouldn't ever send SIGINT so we can ignore that for these purposes

The "something has gone horribly wrong" signal you're thinking of is probably SIGABRT or SIGSEGV, depending on if it was invalid memory access or something else.

You should generally be able to rely on decent software shutting down gracefully upon receiving SIGTERM and if it doesn't, the maintainer should be informed so they can fix it. Indeed, glancing at the i3 source code, they handle SIGTERM, SIGINT, and SIGHUP by gracefully shutting down, and attempting to gracefully shutdown its child processes as well.

A forceful quit implies that SIGKILL is sent, and systemd only resorts to SIGKILL under certain circumstances.

So, in the end I'd say this is probably totally unnecessary, your software is likely all shutting down gracefully already, even if it might not look like it.

/u/k-o-x are you experiencing any issues with your software that are leading you to believe that something isn't exiting gracefully?

8 points

it's a novelty, it's somewhat unusual, there's a little magic in there for some

most of the time a result like this would have been caused by a problem with the machine, but as this was caused by an earthquake, there's a specific event, a moment in time, that is basically tied to this item. It's symbolic as a physical memory of the event, like a souvenir. Some people care, others not so much, it's fine

7 points

RAM access is significantly faster than disk access, and you only have to read from the disk device (not read and write), so it's a lot faster to copy partition-to-RAM

a quick way to check this on linux is to use dd to copy a file into /dev/shm/ or /tmp/; that should show you roughly how fast you can copy from disk into RAM

4 points

ZBrush doesn't print to anything by itself, you'd use it to create a model and export it as an STL, and then use another program to slice it and generate gcode to tell the printer how to print it. This method should work for just about any combination of 3D software and printer.

My printer started life as an Original Prusa i3 MK2S and I've upgraded it over time to a MK2.5 with a full bear frame and some other things. So it's kind-of a custom printer at this point.

I would suggest that if you want an i3, you should look at the Original Prusa i3 MK3S rather than a clone like the Anycubic. Most of the more inexpensive clones do so by cheaping out on parts, instructions, firmware, and support. If you can't justify the expense for that, the Creality Ender 3 Pro is a solid starter printer that can easily be improved and upgraded over time

2 points

Looks like in the first one, she converted $0.39 NZD to $0.27 USD for some reason (which is the correct conversion for that according to xe.com) and then converted that total back to NZD.

I've got no idea what happened the second time, there doesn't seem to be a way to get to $1.66 from $1.39 through partial or double convesion between just USD and NZD

4 points

Yeah, I was going to suggest trying "a dollar thirty-nine US" (or "one dollar and thirty-nine cents US" if she wants to be super formal) which might be worth a shot if Siri gets confused by "buck"

2 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.