* Uprintf prints to the controlling terminal for the current process. */
| 167 | * Uprintf prints to the controlling terminal for the current process. |
| 168 | */ |
| 169 | int |
| 170 | uprintf(const char *fmt, ...) |
| 171 | { |
| 172 | va_list ap; |
| 173 | struct putchar_arg pca; |
| 174 | struct proc *p; |
| 175 | struct thread *td; |
| 176 | int retval; |
| 177 | |
| 178 | td = curthread; |
| 179 | if (TD_IS_IDLETHREAD(td)) |
| 180 | return (0); |
| 181 | |
| 182 | if (td->td_proc == initproc) { |
| 183 | /* Produce output when we fail to load /sbin/init: */ |
| 184 | va_start(ap, fmt); |
| 185 | retval = vprintf(fmt, ap); |
| 186 | va_end(ap); |
| 187 | return (retval); |
| 188 | } |
| 189 | |
| 190 | sx_slock(&proctree_lock); |
| 191 | p = td->td_proc; |
| 192 | PROC_LOCK(p); |
| 193 | if ((p->p_flag & P_CONTROLT) == 0) { |
| 194 | PROC_UNLOCK(p); |
| 195 | sx_sunlock(&proctree_lock); |
| 196 | return (0); |
| 197 | } |
| 198 | SESS_LOCK(p->p_session); |
| 199 | pca.tty = p->p_session->s_ttyp; |
| 200 | SESS_UNLOCK(p->p_session); |
| 201 | PROC_UNLOCK(p); |
| 202 | if (pca.tty == NULL) { |
| 203 | sx_sunlock(&proctree_lock); |
| 204 | return (0); |
| 205 | } |
| 206 | pca.flags = TOTTY; |
| 207 | pca.p_bufr = NULL; |
| 208 | va_start(ap, fmt); |
| 209 | tty_lock(pca.tty); |
| 210 | sx_sunlock(&proctree_lock); |
| 211 | retval = kvprintf(fmt, putchar, &pca, 10, ap); |
| 212 | tty_unlock(pca.tty); |
| 213 | va_end(ap); |
| 214 | return (retval); |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * tprintf and vtprintf print on the controlling terminal associated with the |
no test coverage detected