@@ -689,47 +689,23 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
689689 return r ;
690690 }
691691
692- manager_get_session_by_pid (m , leader , & session );
693- if (!session && vtnr > 0 && vtnr < m -> seat0 -> position_count )
694- session = m -> seat0 -> positions [vtnr ];
695- if (session ) {
696- _cleanup_free_ char * path = NULL ;
697- _cleanup_close_ int fifo_fd = -1 ;
698-
699- /* Session already exists, client is probably
700- * something like "su" which changes uid but is still
701- * the same session */
702-
703- fifo_fd = session_create_fifo (session );
704- if (fifo_fd < 0 )
705- return fifo_fd ;
706-
707- path = session_bus_path (session );
708- if (!path )
709- return - ENOMEM ;
710-
711- log_debug ("Sending reply about an existing session: "
712- "id=%s object_path=%s uid=%u runtime_path=%s "
713- "session_fd=%d seat=%s vtnr=%u" ,
714- session -> id ,
715- path ,
716- (uint32_t ) session -> user -> uid ,
717- session -> user -> runtime_path ,
718- fifo_fd ,
719- session -> seat ? session -> seat -> id : "" ,
720- (uint32_t ) session -> vtnr );
721-
722- return sd_bus_reply_method_return (
723- message , "soshusub" ,
724- session -> id ,
725- path ,
726- session -> user -> runtime_path ,
727- fifo_fd ,
728- (uint32_t ) session -> user -> uid ,
729- session -> seat ? session -> seat -> id : "" ,
730- (uint32_t ) session -> vtnr ,
731- true);
732- }
692+ r = manager_get_session_by_pid (m , leader , NULL );
693+ if (r > 0 )
694+ return sd_bus_error_setf (error , BUS_ERROR_SESSION_BUSY , "Already running in a session" );
695+
696+ /*
697+ * Old gdm and lightdm start the user-session on the same VT as
698+ * the greeter session. But they destroy the greeter session
699+ * after the user-session and want the user-session to take
700+ * over the VT. We need to support this for
701+ * backwards-compatibility, so make sure we allow new sessions
702+ * on a VT that a greeter is running on.
703+ */
704+ if (vtnr > 0 &&
705+ vtnr < m -> seat0 -> position_count &&
706+ m -> seat0 -> positions [vtnr ] &&
707+ m -> seat0 -> positions [vtnr ]-> class != SESSION_GREETER )
708+ return sd_bus_error_setf (error , BUS_ERROR_SESSION_BUSY , "Already occupied by a session" );
733709
734710 audit_session_from_pid (leader , & audit_id );
735711 if (audit_id > 0 ) {
0 commit comments