#### Answer

$$y= \cos x \sin x -2\cos x .$$

#### Work Step by Step

This is a linear equation and has the integrating factor as follows $$\alpha(x)= e^{\int P(x)dx}=e^{ \int \tan x dx}=e^{-\ln \cos x}=\frac{1}{\cos x}$$
Now the general solution is
\begin{align}
y& =\alpha^{-1}(x)\left( \int\alpha(x) Q(x)dx +C\right)\\
& =\cos x \left( \int \cos x dx+C\right)\\
& =\cos x \left( \sin x+C\right)\\
& =\cos x \sin x +C\cos x \end{align}
Since, $y(\pi)=2$, then $C=-2$
Thus, the general solution is:
$$y= \cos x \sin x -2\cos x .$$