being connected to a TTY is not really enough to determine
interactivity in many cases. Let's also check if we have a controlling
TTY.
Inspired by #34016
if (!isatty_safe(STDIN_FILENO))
return 0;
+ /* Also check if we have a controlling terminal. If not (ENXIO here), we aren't actually invoked
+ * interactively on a terminal, hence fail */
+ r = get_ctty_devnr(0, NULL);
+ if (r == -ENXIO)
+ return 0;
+ if (r < 0)
+ return r;
+
if (!is_main_thread())
return -EPERM;
if (!isatty_safe(STDIN_FILENO))
return 0;
+ /* Also check if we have a controlling terminal. If not (ENXIO here), we aren't actually invoked
+ * interactively on a terminal, hence fail */
+ r = get_ctty_devnr(0, NULL);
+ if (r == -ENXIO)
+ return 0;
+ if (r < 0)
+ return r;
+
if (!is_main_thread())
return -EPERM;